Sometimes, randomly, only (it seems) on my PC I've found the first call to FlxG.sound.play() in my game will cause the whole program to crash.
After a bit of poking about, I've managed to narrow it down to SoundFrontEnd.cache(), specifically the bit where it does
return Assets.getSound(EmbeddedSound, true);
I wrapped this with try/catch like this
try {
// load the sound into the OpenFL assets cache
return Assets.getSound(EmbeddedSound, true);
} catch (msg: String) {
trace ("Error: " + msg);
trace (CallStack.toString(CallStack.exceptionStack()));
return null;
}
and got this in the FlashDevelop output window
SoundFrontEnd.hx:143: Error: Not Sound
SoundFrontEnd.hx:144:
Called from openfl._v2.Assets.getSound (openfl/_v2/Assets.hx line 481)
Called from DefaultAssetLibrary.getSound (DefaultAssetLibrary.hx line 1085)
Called from Type.createInstance (C:\HaxeToolkit\haxe\std/cpp/_std/Type.hx line 82)
Called from __ASSET__assets_sounds_startup_wav.new (openfl/_v2/Assets.hx line 1800)
Called from openfl._v2.media.Sound.loadCompressedDataFromByteArray (openfl/_v2/media/Sound.hx line 119)
Called from extern.cffi (C:/HaxeToolkit/haxe/lib/hxcpp/3,1,39/src/hx/Lib.cpp line 126)
Done(1)
In my code I'm simply calling
FlxG.sound.play("assets/sounds/startup.wav");
And most of the time it works fine, but randomly it fails. However it works fine on Android and my Windows laptop...
Has anyone else seen this happen, and is there a way to fix it?