Memory leak with PlayMusic?

Monkey Forums/Monkey Programming/Memory leak with PlayMusic?

SLotman(Posted 2013) [#1]
I was making a new game, everything seemed fine - no problems running on Android / iOS / GLFW, until I tried running my game on WinPhone 8 - where start crashing at random places (tried Monkey from v73 to v76).

Then I went looking on GLFW/debugging to see what was wrong with it, and I see on task manager my game memory increasing with no end.

Thinking I did something wrong, I finally found the culprit: PlayMusic.

Looking at mojo.glfw.cpp I see this:

So apparently, "music" is never released, but allocated every PlayMusic?

Here is a sample code to reproduce the problem:


Running the code above, just by hitting the Space key several times, I went from 35mb to 800mb - and the GC never kicked in to reclaim any of those (program is running for over 10 minutes now, not a single Mb reclaimed).

Don't know if this is happening on ther platforms - I do not even know if this is the same problem affecting the WP8; but for sure on GLFW this is a big issue.

Edit: An HOUR later the memory was reclaimed. Is that how it's supposed to be?!


AdamRedwoods(Posted 2013) [#2]
could be a bug.

I wonder, does PlayMusic() Add to the channel's buffer, so each time it plays it adds more onto the buffer. perhaps when it's done playing it releases the memory. looking at the source, it seems to keep loading new samples.

a better approach would be that if same tune is on the buffer, no new buffer is loaded.

also note that winnrt will not behave the same as glfw. they are different.


SLotman(Posted 2013) [#3]
Yeah... I trying to figure out what is happening on my game with winrt/windows phone 8 (Monkey v76) - the emulator only shows this:

The thread 0xffc has exited with code 259 (0x103).


The thread value changes, but the exit code is always the same.

The game crashes, but even the code generated in debug mode, and running on emulator on debug mode I get no message of what happened - the emulator just returns to the main "tiles" screen (Same happens on device too)

Edit: Downloaded Monkey 76d, now I get this when the game crashes:
The program '[2616] TaskHost.exe' has exited with code -2005270523 (0x887a0005).


OMG! Gotta laugh - searching google tells me that this error means "the hardware is dying" - but I'm getting this on the SIMULATOR!


AdamRedwoods(Posted 2013) [#4]
ERROR_NO_MORE_ITEMS
259 (0x103)
No more data is available.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

looks like a buffer underrun? does it work if you disable all music?


SLotman(Posted 2013) [#5]

looks like a buffer underrun? does it work if you disable all music?



I commented out PlayMusic/StopMusic/Resume/etc on monkeygame.cpp, but I'm still seeing the "thread xyz exited with code 259" :/

I'm testing right now to see if the game still crashes... yup, still crashing :(


AdamRedwoods(Posted 2013) [#6]
sometimes to find a bug like that, you have to load up the VSC++ project file and turn on "link debug info" (it's off by default), then compile (and deploy if you can) from VS. it may give you a better dump info.


SLotman(Posted 2013) [#7]
I am debugging on VS2012... where do I enable this "link debug info"?


AdamRedwoods(Posted 2013) [#8]
Project->Properties->Linker->Debugging->Generate Debug Info


SLotman(Posted 2013) [#9]
It is already set to 'YES/Debug' :(


SLotman(Posted 2013) [#10]
Ouch - something pretty wrong on Monkey/WP8 I guess:


0x887A0005 - DXGI_ERROR_DEVICE_REMOVED

The video card has been physically removed from the system, or a driver upgrade for the video card has occurred. The application should destroy and recreate the device. For help debugging the problem, call ID3D10Device::GetDeviceRemovedReason.

source: http://msdn.microsoft.com/en-us/library/windows/desktop/bb509553%28v=vs.85%29.aspx

...Or maybe it is running out of memory?
http://stackoverflow.com/questions/15906010/no-systemoutofmemoryexception

I'm lost now.


SLotman(Posted 2013) [#11]
Ok, something is definitively wrong - even on my game's title screen (5 images being drawn, 1 music being played and waiting for user input) I keep getting that "thread exited with code 259" thing over and over.

(even commenting out the music part, still happens...)


SLotman(Posted 2013) [#12]
I really don't get it. My game is running perfectly fine on iOS, Android, Flash, GLFW and WinRT. Only when running on WP8 it crashes after a while, always after I finish level 6...

...and it seems to be a memory problem (video?) because if I start the game from level 6, I can go perfectly fine to level 7.

I don't even know anymore if that "thread code 259" is the culprit - I left the game running overnight (it's a quiz game, so it was on a static screen), it didn't crash - but it went all night printing that error in the console window...


SLotman(Posted 2013) [#13]
There is definitively a problem somewhere... I surrounded all my code with try {} catch (), and still on windows phone 8 it is crashing over and over in the same place - and *only* on WP8.

Too bad Visual Studio does not tell me where it's crashing, just throws a exception error, and that's it.

Last one I've got is this: The program '[3860] TaskHost.exe' has exited with code -529697949 (0xe06d7363) 'Microsoft C++ Exception'.


marksibly(Posted 2013) [#14]
Nice find on the glfw front - the app is taking so long to reclaim song memory because it's taking so long to trigger a GC. Will fix soon.

However, it doesn't relate to winrt which uses a high level media player and doesn't allocate anything.

I tried profiling in msvc but got 'no call tree data' or something when trying to view results. Anyone have any idea what's up here?


SLotman(Posted 2013) [#15]
Maybe this post can help? I don't know much about profiling in MSVC, but at least the last post someone said to be having the same problem, and could run it without running as admin...

http://social.msdn.microsoft.com/Forums/en-US/c609d76c-be22-4ffb-858c-73ccab591a78/vs11-2012-profiler-not-producing-any-call-tree-data-win-8-64?forum=vstsprofiler

Here I can't even start anything - the "analyse" option on VS2012 tells me that there is no project available for profiling :(


marksibly(Posted 2013) [#16]
> Here I can't even start anything - the "analyse" option on VS2012 tells me that there is no project available for profiling :(

You need to select 'analyze windows phone 8 app', further down the debug menu...

This bit works for me, the app runs, log is processed etc, only I end up with 'no call tree data'.


SLotman(Posted 2013) [#17]
I tried with my game... it actually ran, but didn't show anything, anything at all in log or whatever - not even when the game crashed, and neither this 'no call tree data'.

I'm stumped. I tried to comment out music and sounds, the the game still crashes at one specific point. If I go straight to the beginning of that stage (skipping the ones before) I can pass without any crashes.

Sometimes the phone just stops responding to touch altogether (even on simulator) for no apparent reason.

Maybe this has something to do with Image.Discard()? I'm using that a lot, since I'm loading/unloading things from stage to stage... (btw, I tried removing the image.discard, only setting images to null - and got no improvements)

Would it help if I sent you the code? (It's a quiz game, all in brazilian portuguese, but I could change it so any answer selected would be right heh).


SLotman(Posted 2013) [#18]
Update: Latest Monkey (77b) doesn't crash anymore - but something even more strange is happening both on emulator and in the real device now: it stops responding for any touch events in the display after a while. The windows/back/search buttons still works, but even if I exit the app and go back to the main screen, the touch display wont work - I have to force restart (pulling the battery out!) my phone for it to go back to work again.

A new error also popped up: "'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded 'C:\windows\system32\System.Runtime.Serialization.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled." - just once before it stop responding. Don't know if it's related or not.