Random crashes of my app on WP8 phone

I just finished porting my first WP8 game for Corona Cards today (BTW thank you Corona for making it free!). It’s just a board game that was originally on iOS and Android, and the biggest change I made was in the code where I had numbered the board from 1 to 100. For the numbering I used to have a FOR loop with display.newText going through all the squares, but I saved a few seconds of lag on WP8 by using bitmapped numbers made with bmGlyph.

Now, however, when I run the game I keep running into random shutdowns of the game. Uggghhhh… It sometimes happens when a player’s piece is moving on the board. I am using a Nokia 635 which has 512MB of RAM.

Here are two of the messages I got on the console (I got no other debug info from the output):

One time it happened, at the Game Over overlay, when I pressed a button to return to the game’s main menu scene:
“Insufficient memory to continue the execution of the program.”
“The thread 0x9a0 has exited with code 0 (0x0).”
“The program ‘[3968] TaskHost.exe’ has exited with code -2147220978 (0x8004020e)”

Another time, I believe while a player was moving (similar, but no memory issue):
“The program ‘[3532] TaskHost.exe’ has exited with code -2147220978 (0x8004020e).”

A couple more crashes were noticed when I pressed the phone’s Back button during the game.

Now, I did trim a few things here and there, by removing background music and decreasing background image size. But still that did not help.

Any ideas or anyone else have this problem?

It sounds like you are running into OutOfMemory exceptions.

A 512 MB WP8 device is the lowest memory device you can get (worst case scenario) and is definitely good to test with, because low-end WP8 devices are the most popular devices.  On these phones, your app does not get to use all 512 MB of memory.  Your app is typically limited to 180 MB of RAM.

   https://msdn.microsoft.com/en-us/library/windows/apps/jj681682(v=vs.105).aspx

You can verify that this is the issue by running your app via the WP8 emulator with a virtual device that supports more than 512 MB of RAM.  What you need to do is compile your app for x86 as shown here…

   http://docs.coronalabs.com/coronacards/wp8/build.html

And on the toolbar, notice that the [> Emulator] button is a drop-down box.  The emulator devices that do *not* have “512 MB” to the right of the device name support more than 512 MB of RAM.

The idea is to confirm that you are actually running into an out-of-memory issue (it sounds like you are) or at least to confirm if there is a 2nd issue happening as well so that you can debug 1 issue at a time.

Now, if you are running out of memory, then there is really only 2 solutions to this problem…

  • Solution #1

The best solution of course is to reduce the amount of memory you app eats up at runtime.  This may mean loading smaller images.  Or loading less images and audio at a time.  If you are loading huge audio files, then perhaps you should consider streaming them instead.

  • Solution #2

The other way to handle it is to not support low-memory devices.  This involves adding a ID_REQ_MEMORY_300 entry to your app’s manifest file as described in Microsoft’s documentation in the link I posted up above.  Note that I don’t recommend this because low-memory/low-end WP8 devices are very popular.  Like over half of the WP8 market.

Thanks for the tips.  Yeah I do not want to limit my audience by preventing 512MB devices.   I’ll try running the emulator in 512MB device mode to ensure I can reproduce the problem there before I move onto a > 512MB emulator.

I don’t think my app is eating up a lot of memory.  I’m looking at the numbers on the right side of the emulator, and it looks like I’m usually at around 4500 (kB?) of texture memory being used up, both on the phone and the emulator. (EDIT: Okay that may be a lot!)

BTW, I just ran it on the emulator, and after about 4-5 minutes of play the game screen froze up and some of it changed to a black background.   Will now try on a higher-RAM device.   I think this message appeared at the same time, not sure:

“The thread 0xce8 has exited with code 0 (0x0).”

I’m pretty sure your app is using more than 4,500 KB of memory.

For example, your image files (*.PNGs, *.JPEGs, etc.) have to be decoded to 32-bit uncompressed bitmaps when submitted to the GPU as textures.  So, it doesn’t matter how smaller your PNG or JPEG files are.  They’ll all get decompressed into memory at runtime.  This is how it works on all platforms too (Android, iOS, Mac, Windows).  So, a 512x512 image is made up of 262,144 pixels, multiplied by 4 byte (for 32-bit color) per pixel, for a grand total of 1,048,576 bytes used in memory… or just over 1 MB.

You might also want to check Visual Studio’s “Output” panel for any Lua runtime errors that might be occurring.  Although, I suspect you might already being doing so.

Also, the following message…

>>  “The thread 0xce8 has exited with code 0 (0x0).”

…is nothing to worry about.  It’s not an error or warning.  This is Visual Studio just telling you that a thread has finished executing.  You’ll see the same thing happening in Microsoft’s own sample projects too.

Yes, I’m using the output panel (CTRL + ALT + letter O).

I cut a bunch of stuff out of my game last night, so it’s totally gimped, but I’m still running into these random shutdowns. You may be right that my game has too many things going on… I mean I have the background image, the game board image, the numbers on the board (a hundred of them), a transparency on top that shows the bad guys on the board, and then the player pieces and dice.   I even tried removing the 100 numbers and I still had issues.  I never had this problem on a 512MB Android phone.

Next, I ran some debug Corona code to show me the System Memory (collectgarbage(“count”)) and Texture Memory (system.getInfo(“textureMemoryUsed”) at every 1-second interval.   NOTE: I also realize I have an interstitial ad that is displayed at the start, and is preloaded again after the ad is shown (otherwise it won’t show the interstitial again).

When I start the app, it goes to the main menu (ad is preloaded):

System Memory used: 988 kB

Texture Memory used: 8 kB

Start the game (interstitial now shown):

System Memory used: 1650 kB   <— Big increase – board is being shown underneath

Texture Memory used: 9 kB

Close the ad:

System Memory used: 1650 kB   <------ Still remains…

Texture Memory used: 8.7 kB

Start playing (pieces moving, dice rolling):

System Memory used: 1800kB   —> Remains around this amount while playing, even when you go back to game menu and restart

Texture Memory used: 10.8 kB

After about 5 minutes of play, the game shuts down with code -2147220978 (0x8004020e) again:

System and Texture memory used: Same as the amount above.

So, this is all the info I have so far.  The game uses up 1.8MB of RAM.   Is this acceptable?

Just another note - I do have a couple of display.newText objects on the screen that get updated,  just the player’s name and their position (the square’s number) on the board.   There are a few more but they are static.   I don’t know if this would have an effect?

Usually when someone runs into a black screen on WP8, it’s because they attempt to use a feature that’s not supported by Corona on WP8 yet.  Although, if this were the case, you should see a Lua runtime error of some kind in the Visual Studio output panel.  Maybe you should double check that Lua is able to print to Visual Studio’s output panel okay (it should).  Try putting a print() function in your “main.lua” to see if it gets outputted to Visual Studio correctly.

Another thing to double check is to make sure that all of your Corona project files are actually getting bundled into the WP8 *.xap file.  You have to explicitly tell Visual Studio to do this by settings the file’s “Build Action” property to “Content”.  Have a look at the instructions here…

   http://docs.coronalabs.com/daily/coronacards/wp8/portapp.html#copying-project-files

Also, calling display.newText() will work and is okay to do.  In fact, it makes sense to use display.newText() on WP8 if you’re fetch text from a source that you don’t have any control over, such as Twitter or Facebook.  It’s just very slow to generate the text bitmap on WP8.

One last thing.  Which build CoronaCards build # are you using?

In Visual Studio’s “Solution” panel, if you left click on your project’s “References\Corona Framework” node, it’ll show the version in the Properties panel.

Hi Joshua,

My Corona Framework version is 14.0.2511.0. This is the last public release. Has a lot changed for Corona Cards WP8 in the daily builds?

I’m not using any special feature for the app, it’s actually quite basic… I’m using AdMob for ads.  I do have Widget Candy but that’s in my Settings scene, which I didn’t use during the times it crashed.   I had already set the Built Action to Content, like it said in the porting guide.

The LUA print() command works fine in the Output console when the Nokia or emulator is running, and that’s how I was able to get those memory stats in my other reply.

I looked up the -2147220978 (0x8004020e) error code on google, and it means “Unable to find a trustee name that corresponds to a security identifier provided by the user.”     Could that have something to do with the license file?

I could share my project folder with you privately if you’d like to check it out.

>> I could share my project folder with you privately if you’d like to check it out.

That would be a big help.  Because I’m just guessing at what the cause is at this point.  You can just zip up your project and submit it to us via the “Report a Bug” link at the top of this web page.  Also, mention my name (Joshua Quick) and provide a link to this forum thread in the bug report too.  That way our tech-support group will know to send it my way.  Oh and we’d appreciate if you would click “Build\Clean” in the Visual Studio menu to delete all of the compiled files before zipping it up too.  :slight_smile:

I should have time to look into this early next week.

Other than that, I’m not sure how else to help.  You could try the newest daily build, but we haven’t made may WP8 specific changes since the last release other than core features that were implemented on all platforms.  There is only 1 outstanding bug in Corona on WP8 that I’m aware of where a Lua print() with message that is over 10 kb will cause a crash, but that’s an extreme edge case that won’t happen to most people.  I’ll have that issue fixed by next week.  There was a known black screen issue that would happen to some people after doing a suspend/resume, but that was fixed by build #2506 (I looked it up).

Great, thanks a lot, I’ll try to do that if I can’t manage to fix it.   In the meantime I’m going to try the daily build.

Appreciate your help…

Hi Joshua, have you had a chance to look at my bug report?

Sorry about the late response.  Yes, I’ve had a chance to play with your app.

I wasn’t able to reproduce the crash running build #2583.  Although I had AdMob disabled when I tested it.  I’m wondering if that had anything to do with it, but I also know other Corona developers got AdMob working just fine on WP8.  I played it until I won the game a few times, but no crashes.  Are you able to get it to crash consistently anywhere?

I tested your app on a low-end Nokia Lumia 620 running OS version 8.0.

I also tested it on a Nokia Lumia 920 running OS version 8.1

I just tested your app again using a Nokia Lumia 635 that I just acquired today.  I also enabled AdMob so that your code will display its interstitial ads (seems to always display when you start a new game from the main menu).  It’s still not crashing on me.  I also suspended/resumed your app several times and all of the image reloaded fine.  As well as disabling WiFi and the AdvertiserId in case it had an effect on AdMob.

The only crasher that we’ve found on WP8 recently is if you attempt to print() a string containing a ‘%’ character.  I don’t think your app does that, but it’s something we’ve found and fixed in a recent daily build.

Thanks so much for taking the time to look into it. I’m surprised it did not happen on yours. I had bizarre artifacts on my 635 too sometimes when it didn’t crash. Later I had the same shutdown issue when building a different app, which was a math quiz game.

One thing to note is that the emulator in Visual Studio froze once when playing the original game. So I’m wondering if there is something that may have been corrupted during the build process. I built and ran it many times though. I will clean out my output folder and rebuild it and try again.

The only other thing I haven’t done yet is test with the exact CoronaCards build # that you are building with.  I was using a fairly recent daily build.

I had tried the last public build for CoronaCards and later the latest daily build (from last week). When I have a chance again I’ll try with the latest build and clean out my build folder and let you know how it goes.

Interesting, I just tried it on the Debug x86 emulator for the 4-inch 512MB device, and while i was playing, the game board suddenly went all black. I pressed the New Game button and then the app shut down. I got that same -2147220978 (0x8004020e) error too, which I had only seen on the phone previously.

According to http://www.symantec.com/business/support/index?page=content&id=TECH12638, that error code refers to:
“Unable to find a trustee name that corresponds to a security identifier provided by the user.”

And at https://msdn.microsoft.com/en-us/library/windows/desktop/dd542643%28v=vs.85%29.aspx
“Cannot modify or delete an object that was added using the COM+ Admin SDK”

I also ran it on the actual phone. In one instance of the game, when both the player and computer have had a turn, I pressed the red Home button. When it went back to the main menu the background was black and the text on the buttons was blotted out by black. (See photo below)

I’m using the latest build of CoronaCards.

MepxdQnl.jpg

I’m not sure what else I can do to help you.  I’ve tested it on 3 different WP8 devices and I can’t reproduce it.  And no one else is running into this problem either.

The only thing I can think of is that you’re not actually running the Corona library build # that you think you are.  My last bit of advice is to add a…

   print("Corona Build = " … tostring(system.getInfo(“build”))

…to your “main.lua” file.  This will print the build # of the Corona library.  If it’s not using the same build # that you are using in Visual Studio, then you have an incremental build issue.  If that’s the case, then you need to delete your app from the WP8 device, and then do a clean build in Visual Studio via the “Build\Rebuild” in the menu.

Hi,
According to the debug info that you suggested, I am using build 2015.2589, which was the latest build from a few days ago when I installed it. I have also rebuilt it from scratch and loaded it onto my phone.

Just now I played two full games. At the end of the second game, when the Game Over overlay asked if I wanted to play again or go Home, I selected Home. I ended up getting the same screen shown in the screenshot in my last reply (blackened background, blackened text, no title banner).

Next, I pressed the “Settings” option (third option in the menu) and the settings screen came up, but with the black background.

Went back to the main menu and everything went back to normal (title, menu options), but the background was still black.

So, I selected a One Player game, and the screen froze at black. Then I got the following show up in Visual Studio:

“An unhandled exception of type ‘System.OutOfMemoryException’ occurred in System.Windows.ni.dll
Additional information: Insufficient memory to continue the execution of the program.”

The strange thing is, I had no memory issues or leaks when when I ran the Corona memory debug output. I never had these strange issues in Android and iOS with the same app either. This is a very basic game so I don’t see how memory usage could be that high.

I couldn’t get a stacktrace dump because apparently I need to turn off something (forgot what it was, but I turned it off now). I’ll try to get more info later. If I can’t get this to work, I’m just going to give up and return this $100 phone to Microsoft and deal with the $20 spent on developer registration. I can’t afford to waste my time on this anymore. :frowning: