Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

1.72 Linux - crash-bug if sound can't be initialised.

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Micha
Commodore
Commodore
Posts: 815
Joined: Tue Sep 02, 2008 2:01 pm
Location: London, UK
Contact:

1.72 Linux - crash-bug if sound can't be initialised.

Post by Micha »

I've found a crash bug in SDLMusic.m (which unrelatedly stayed as a DOS/Mac text file when I checked it out) when the sound system can't be initialised.

Here's a (probably very nasty) patch which works around it - there's possibly much better ways to do it within the codebase.

Code: Select all

Index: OOSDLSound.h
===================================================================
--- OOSDLSound.h	(revision 1769)
+++ OOSDLSound.h	(working copy)
@@ -61,4 +61,6 @@
 
 - (NSString *)name;
 
++ (BOOL) isSoundOK;
+
 @end
Index: OOSDLSound.m
===================================================================
--- OOSDLSound.m	(revision 1769)
+++ OOSDLSound.m	(working copy)
@@ -89,7 +89,8 @@
 
 + (void) setMasterVolume:(float) fraction
 {
-	if (!sIsSetUp)  [self setUp];
+	if (![self setUp])
+		return;
 	
 	fraction = OOClamp_0_1_f(fraction);
 	int volume = (float)MIX_MAX_VOLUME * fraction;
@@ -108,7 +109,8 @@
 
 + (float) masterVolume
 {
-	if (!sIsSetUp)  [self setUp];
+	if (![self setUp] )
+		return 0;
 	
 	return (float)sEffectiveMasterVolume / (float)MIX_MAX_VOLUME;
 }
@@ -116,7 +118,8 @@
 
 - (id) init
 {
-	if (!sIsSetUp)  [OOSound setUp];
+	if (![OOSound setUp] )
+		return nil;
 	return [super init];
 }
 
@@ -124,7 +127,7 @@
 - (id) initWithContentsOfFile:(NSString *)path
 {
 	[self release];
-	if (!sIsSetUp && ![OOSound setUp])  return nil;
+	if (![OOSound setUp])  return nil;
 	
 	return [[OOSDLConcreteSound alloc] initWithContentsOfFile:path];
 }
@@ -139,7 +142,14 @@
 
 + (void) update
 {
-	[[OOSoundMixer sharedMixer] update];
+	OOSoundMixer * mixer = [OOSoundMixer sharedMixer];
+	if( sIsSoundOK && mixer)
+		[mixer update];
 }
 
++ (BOOL) isSoundOK
+{
+  return sIsSoundOK;
+}
+
 @end
Index: SDLMusic.m
===================================================================
--- SDLMusic.m	(revision 1769)
+++ SDLMusic.m	(working copy)
@@ -24,6 +24,7 @@
 

 #include "SDLMusic.h"

 #import "OOLogging.h"

+#include "OOSDLSound.h"

 

 #define kOOLogUnconvertedNSLog @"unclassified.SDLMusic"

 

@@ -72,8 +73,9 @@
  */

 - (id) initWithContentsOfFile:(NSString*) filepath

 {

+	if( ![OOSound isSoundOK] ) return nil;

+

 	[super init];

-

 	music = Mix_LoadMUS([filepath cString]);

 	if (!music)

 	{

 /
The glass is twice as big as it needs to be.
Post Reply