crash at app exit with CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic


#1

Hi,

I just started my first project with cocos2d-x,

After adding a few lines of code, I got a crash on win32 at app exit,

the crash appears when I added this line of code:

CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(“music/music3.mp3”);

The music plays well but at exit I get an exception in vs debug/win32:

Unhandled exception at 0x76aca4b9 in MyGame.exe : 0xC0000005: Access Violation 0xfeeefeee.

vs point me the file C:Files\Microsoft Visual Studio 9.0\VC\crt\src\crtexe.c but I dont think it s revelant

any ideas?

does I have to release something if I use the audio engine?


#2

On win32, you should invoke CocosDenshion::SimpleAudioEngine::sharedEngine()->end() before exiting.


#3

thanks,

I added the code in AppDelegate destructor , the crash is gone, let me know if it s correct

AppDelegate::~AppDelegate()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    CocosDenshion::SimpleAudioEngine::sharedEngine()->end();
#endif

}

#4

Yep, it’s right.
I think this code is also available on other platforms, so you don’t need to use #if xxx.