First patch: friendly sound errors

First patch: friendly sound errors

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
TheBlasphemer
Posts: 20
Joined: 31 Jul 2006, 13:13

First patch: friendly sound errors

Post by TheBlasphemer »

Alright, finally got my copy to compile, and the first thing that pissed me off was the sound error when trying to use XTA v0.7.
I'm ok with the fact that old mods are not compatible, but completely exiting because a sound file isn't found?! come on! do you expect windows to BSOD you when it can't find a sound for an event? No, ofcourse not, you expect it to write a warning to the logfile, and then go on without it!

So yeah, I tracked it down quite quickly, and this is what I came up with. Basically what it changes is this:
  • Loading a non-existing sound
    Previous behaviour: MessageBox and disable sound altogether.
    New behaviour: if possible, display an error in the info-log, keeps sound enabled.
  • Getting ID for non-existing sound
    Previous behaviour: if loading failed, returns the number associated with a non-existant wav-file. Basically: random number ;)
    New behaviour: return id 0 if sound is not found and can not be loaded.
  • Getting buffer of non-existing or invalid sound id
    Previous behaviour: start doing stuff with an uninitialized pointer -> crashy!
    New behaviour: return -1 if an invalid ID
One thing that might be argued about this solution is that it will probably generate an error for each time the mod/engine tries to access the sound, while one-time should be enough. I could do a quick-fix to only allow one warning, but that would also mean that not all wav-ids would be allocated, and it would either require a few big changes, or a very nasty hack, neither of which I feel doing now ;)

As I am unaware of how to properly send in a patch, and cannot find an attach function on this forum, I am just going to paste the .diff file here:

Code: Select all

Index: System/Platform/Win/DxSound.cpp
===================================================================
--- System/Platform/Win/DxSound.cpp	(revision 1716)
+++ System/Platform/Win/DxSound.cpp	(working copy)
@@ -130,9 +130,9 @@
 
 	// Create the sound buffer object from the wave file data
 	if( !CreateStaticBuffer(name.c_str()) )
-	{        
-		MessageBox(0,"Couldnt create sound buffer","Sound error",0);
-		noSound=true;
+	{   
+		if (info)
+			(*info) << "no such sound: " << name.c_str() << "\n";
 		return -1;
 	}
 
@@ -159,13 +159,15 @@
 		InitFile(name);
 		si=waveid.find(name);
 	}
-	int ret=si->second;
+	int ret=(si!=waveid.end())?si->second:0;
 	POP_CODE_MODE;
 	return ret;
 }
 
 int CDxSound::GetBuf(int id,float volume)
 {
+	if(id<=0 || id>=loadedSounds.size())
+		return -1;
 	SoundInfo* s=loadedSounds[id];
 	int num;
 	if(s->freebufs.empty()){
@@ -348,7 +350,7 @@
 		buf = new Uint8[fileSize];
 		file.Read(buf, fileSize);
 	} else {
-		handleerror(0, "Couldnt open wav file",path.c_str(),0);
+		//handleerror(0, "Couldnt open wav file",path.c_str(),0);
 		return false;
 	}
 	// Read the WAV file
So there, I hope this contribution is useful ;)
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Post by Forboding Angel »

THis probably flew over most peoples heads, however, thank you for the help with this!

I can definately say that you're making some poor bastard's life a little bit easier ;p
patmo98
Posts: 188
Joined: 09 Jan 2006, 17:51

Re: First patch: friendly sound errors

Post by patmo98 »

TheBlasphemer wrote: As I am unaware of how to properly send in a patch, and cannot find an attach function on this forum, I am just going to paste the .diff file here:
You did exactly the right thing. First post the patch to the board. Second, cross-post to the mailing list.
j5mello
Posts: 1189
Joined: 26 Aug 2005, 05:40

Post by j5mello »

Yes posting here is good but prepare for all of the community to pass judgement on you. However u really only have to worry about what the devs think.

/me bestows TheBlasphemer with a Shield of Forum Protection with +50 resistance to non-coder-suggestions and with the Continue-Making-Patches Gautlets with +50 resistance to people-who-think-a-patch-will-unbalance-AA-and-is therefore-bad.
Post Reply

Return to “Engine”