Verify this is a bug, please.

Monkey Targets Forums/Flash/Verify this is a bug, please.

CGV(Posted 2013) [#1]
I'm finding that in Flash games where sounds are played setting #MOJO_AUTO_SUSPEND_ENABLED to True causes a crash when the Flash window regains focus, but never the first time. That is, it can lose and regain focus once without any problem but if it happens again the app crashes with the below error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at gxtkAudio/Suspend()

Sometimes it takes several suspend/resumes to make it crash but it always crashes eventually.

I've tested apps from the bananas folder, diddy examples and my own code using Monkey 71c and 73a and Flex sdk's 4.0, 4.5 and 4.6 and this only happens in apps that play sound but only after the first sound has played. If the app runs without playing a sound suspend/resume works normally but once a sound is played the crash is inevitable.

I felt Monkey had matured enough so I'm writing my latest Flash game in it and everything was going great until I ran into this problem.

Searching the forums I see no one else has ever reported this bug so, can anyone else reproduce it or is it just my box?


SLotman(Posted 2013) [#2]
Bug confirmed!! I click anywhere else, and when I click back, I got this:
Monkey Runtime Error : TypeError: Error #1009
MonkeyPro73a/modules/mojo/audio.monkey<49>
MonkeyPro73a/projects/dwcp/dwcp.monkey<1964>

dwcp.monkey, line 1964 is just this:
Function PlayAudio:Void(s:Sound)
	If DWCP.audioVol>0 Then
		PlaySound s, DWCP.curSound <--- crashes here
		DWCP.curSound = DWCP.curSound + 1
		If DWCP.curSound > MAX_CHANNELS Then DWCP.curSound=0
	End If
End Function


Not even checking "s" for null avoids the crash.

And another bug: Error "" isn't stopping the music being played. The old build of the game (this one) if you click on "Quit" the music stops. The new one I built here, the music keeps on playing...


SLotman(Posted 2013) [#3]
Tracing the problem, it crashes on mojo.flash.as, on PlaySample, at this line:
if( chan.state!=0 ) chan.channel.stop();

Commenting it out seems to fix it!
Even better, I replaced with this:
if( chan.state!=0 ) 
{
  if (chan.channel) chan.channel.stop();
}

And no more crashes :)


CGV(Posted 2013) [#4]
Nope, sorry SLotman, that's not working for me :(

I both commented out the line and replaced it with the code you posted and still got the crash in both cases. I tried different versions of Monkey and different Flex sdk's and it crashed in all cases.

My games are crashing on the Suspend method so I tried commenting out that same line in that method to no avail.

I then commented out all of the code in the Suspend and Resume methods and that worked for me. No more crashes but of course now the music doesn't stop playing when the game loses focus.

The fact that it's crashing at different places for us suggests the bug is somewhere else entirely but I think we're getting there.


CGV(Posted 2013) [#5]
I just discovered in bananas/mak there is a suspendtest app which demonstrates the auto suspend feature and it works perfectly so now I'm at a complete loss.


bazmonkey(Posted 2013) [#6]
I'm using monkey v66b, so my info could all be old news or irrelevant, but I've been trying #MOJO_AUTO_SUSPEND_ENABLED and I can reproduce a Flash freeze when 2nd sound plays after a suspend/resume. I can fix it by manually calling StopChannel() on the appropriate channels in OnSuspend. Not sure how this fits in with the replies above, I guess I bypass the bug by stopping the channel myself (but I shouldn't need to?).

Similarly, in html5 it repeats the last sound played every time the game is resumed (rather than crashing) - but again using StopChannel 'fixes' it. Thats how I spotted it in the first place.


CGV(Posted 2013) [#7]
Similarly, in html5 it repeats the last sound played every time the game is resumed (rather than crashing)

Interesting, that's what happens in Flash if I build for Flash 9. If I build for 10 or 11 though, it crashes.

I've decided Monkey still has some baking to do and since I'm presently only interested in Flash development I'm going back to that for the rest of this year. Maybe when I come back it will be all sorted out.


CGV(Posted 2013) [#8]
UPDATE: The latest experimental version of monkey(v37b) fixes this problem but it does break all Diddy written apps in the process.

I guess we'll have to wait for it to stop being experimental for therevills and Samah to fix what broke.