[Solved]Error in OggSoundManager destructor


31-01-2010 18:43:03

I get this error consistently and I have no idea why.

When I exit my program and the OggSoundManager is doing its cleanup and shutting down it tries to delete parameters of an object that don't exist.
if ( mActionsList )
SoundAction obj;
// Clear out action list
while (mActionsList->pop(obj))
// If parameters specified delete structure
if (obj.mParams)
cSound* params = static_cast<cSound*>(obj.mParams);
delete mActionsList;

(I'm using the boost threads).
obj.mParams is a uninitialized local variable that gets the value of 0xcccccccc after the mActionList->pop(obj) method.
Thus when it tries to stet the stream to null on the params variable it throws an exception.

In my handling of the manager in the game I currently only do the following tasks: I create/add sounds to the manager. I pause,stop,play them (I never delete/remove them). I leave the removal to the manager.

I'm also loading the manager as a plugin. I do not "new" it anywhere.


01-02-2010 15:43:40

Hmm, when are you exiting?

That list is used to fire off events to the second thread to perform some sound operation then it should automatically clean itself up when its completed. Can you create a test app displaying the issue or find out what type of event it is trying to process at that point?



01-02-2010 17:51:58

Currently this is the process.
I press an input key, it triggers a bool to cause the main game loop to stop.
I exit my game logic loop, delete/destroy my subsystems (here I would stop and/or destroy all sounds on the sound manager) , I clear the scene and then Ogre cleans it self up. In the ogre cleaning itself up part it cleans its plugins and the destructor of the SoundManager is called.

I'm trying to dig a little deeper to see if the actionlist isnt being updated by a certain thread when it needs to be or something else, but haven't found anything else.

All I do within the system is I add two sounds. I play one them at the start of the program and then I do nothing until I shutdown. Right before the shutdown, the stop and destroy actions I believe are put onto the action list and I"m not sure when they are evaluated.


01-02-2010 23:02:59

Hmm, I guess shutting down that way may cause an issue as its possible ogre destroys the sound manager BEFORE it has chance to clear the actions list, maybe I can find a way to make the destruction wait until the actions list is cleared, otherwise do you get an error if you let the sound manager stop/destroy the sounds itself?

Looking at the code its only creating a sound that uses the mParams variable so are you possibly creating a sound just before you quit?


02-02-2010 02:17:54

Currently I get non-deterministic results when I just stopAllSounds. I'd say about 60% of the time I get the error.


02-02-2010 09:58:01

I can't see anything wrong in the code, the unintialised variable is set to a valid object if the mActionsList has some elements in it, pop() returns true/false depending on list contents, obviously its returning true and falling into that block, but if obj is garbage maybe the memory is getting corrupted elsewhere?


10-03-2010 19:04:49

I'm trying out OgreOggSound for the first time today, and I just ran into the same error. Reproducing it isn't a problem for me. I'm explicitly creating and destroying the sound manager, and all I have to do is call destroyAllSounds() or stopAllSounds() immediately before deleting the sound manager, i.e.:

delete mSoundMgr;

where mSoundMgr is the OgreOggSoundManager object. stopAllSounds() has this snippet of code:

SoundAction action;
action.mAction = LQ_STOP_ALL;

which doesn't initialize action.mSound or action.mParams. When the destructor is called immediately afterward, that action turns up in the action list, the uninitialized value for mParams passes that if( obj.mParams ) test, and it crashes.

Of course, poking around further, it looks like the destructor cleans everything up and I didn't need to stop or destroy anything beforehand anyhow. Live and learn. :)


10-03-2010 20:23:12

Yes thats correct, you don't need to clean everything up manually but thanks a lot for pointing that issue out! :oops: