Very strange (android) building bug

Hey @CoronaStaff ,

I got a really weird building bug, that breaks my entire project.

Sadly I’m not able to reproduce it on a smaller scale, so I hope my discription is enough to suggest a solution.

In short

I got a number of functions called in a row (around 10) and each function calls other stuff inside itself. When I remove one of those functions (no matter which) everthing works fine, but when they are all in, the built apk file is around 3,5 MB smaller and crashes on start.

The setup

My project is devided into several modules (files) that are all loaded at the start. Every screen in my game is a single file (I don’t use composer) and there is a “master” module that handles all the screens.

At the start of the app this master module calls the “draw” functions of every screen in the game one after another, which than create all the games graphics.

The problem

In the simulator everything works fine and when I build the project (for android) there are no errors or warnings, it just builds the project. But when I test the app on a device, it crashes immediately after launch (sometimes a previously created graphic is shown for hlf a second).

The testing

I tested my code and the builds alot after that. Fortunetly I had a working build one day earlier and the strange thing is, that the newer not working build was about 3,5 MB smaller, than the working one. (assets stayed the same) I unpacked both APK files to look for the cause of the loss in size. In fact some off the classes.dex files were missing or smaller.

I used that as a starting point, commented out everything and commented it back in one after another. Finally, I found the cause. As I mentioned above I loaded all screens one after another and when I removed the last screen from this list, the build worked fine.

The thing is, it doesn’t matter, which one is the last screen. I switched their order and as long as the draw function of the last screen (no matter which screen was the last) wasn’t called, the build worked fine (right file size) and worked on my device.

But it gets stranger from here on:

I removed everything from that last function, so the last draw function (which caused the bug) was empty, and commented it back in. Despite that the bug still occured!

As the bug basically occured an calling an empty function I thought it should work with any function. So I removed the last draw function call and replaced it with math.random(). And guess what, the bug occured.

--this build works TitleScreen:draw(graphicObj) PregameScreen:draw(graphicObj) GameScreen:draw(graphicObj) PauseScreen:draw(graphicObj) ResultScreen:draw(graphicObj) VideoScreen:draw(graphicObj) RestartScreen:draw(graphicObj) OptionsScreen:draw(graphicObj)

--this build fails TitleScreen:draw(graphicObj) PregameScreen:draw(graphicObj) GameScreen:draw(graphicObj) PauseScreen:draw(graphicObj) ResultScreen:draw(graphicObj) VideoScreen:draw(graphicObj) RestartScreen:draw(graphicObj) OptionsScreen:draw(graphicObj) math.random()

It also works to put the last function into the function before:

--this build fails TitleScreen:draw(graphicObj) PregameScreen:draw(graphicObj) GameScreen:draw(graphicObj) PauseScreen:draw(graphicObj) ResultScreen:draw(graphicObj) VideoScreen:draw(graphicObj) RestartScreen:draw(graphicObj) OptionsScreen:draw(graphicObj) CreditsScreen:draw(graphicObj)

--this build works TitleScreen:draw(graphicObj) PregameScreen:draw(graphicObj) GameScreen:draw(graphicObj) PauseScreen:draw(graphicObj) ResultScreen:draw(graphicObj) VideoScreen:draw(graphicObj) RestartScreen:draw(graphicObj) OptionsScreen:draw(graphicObj) --at the top of this function CreditsScreen:draw(graphicObj) is called

The thoughts

Soo, I think it maybe has something to do with the fuction stack, maybe there are too many functions on that stack (which the compiler couldn’t handle)? I don’t know. I tested with the current stable and daily builds unfortunetly I was not able to test for iOS yet.

Would be really great to get some help here (in fact I’m quite nervous, as I have to fullfill a milestone on monday), thanks alot allready :slight_smile:

If there are any detail questions, let me know.

Are there any errors in the console log?

What version of Corona is it happening with?

Did you change Corona Versions in the time when this was working and when it doesn’t?

Do you have a lot of “local” variables/functions?

Rob

Hey Rob,

thanks for your reply.

On simulator console I got no errors or warnings. On device I was only able to use an logcat app (as I did not get my device to show up in the adb) which shows no messages as well.

It occurs with current public version ( 2016.2906 ) and several daily builds (tested 2016.2935 - 2016.2938).

I did not change the version before the issue (only afterwards, to check if it was a version issue) and as I said, if remove the function call it works fine in all versions.

Inside the scope the functions are called there are about 30 local variables. (2 declared in the same block, the rest are declared outside, but only 10 of those are used inside the same block).

In the absence of any errors, what is happening? Is the app just exiting?

And the really important question. Are you by any chance using a global named “debug”?

Have you disabled runtime errors in your build.settings?

Nothing I’ve seen points to a stack overflow and that would generate a stack overflow error.  You are limited to 200 locals in a module and 60 upvalues, but both of those generate messages.

And are you on Windows or a Mac?

Rob

It simply says in german:

“Appname” wurde beendet. - which translates too - “Appname” has been terminated.

I do not use a global named “debug” and I haven’t disabled runtime errors in the build.settings. (I also use the debug keystore)

Well, as I wrote I assume it’s a compiler/building thing (because of the shrink of the file size by 3,5MB), so I didn’t mean a stack overflow in the app but in the compiler/building process.

Right now I’m on PC but I will check on Mac tomorrow.

Gretings

Torben

Hey Rob,

thanks for your help again.

The thing is, I was able to bypass the issue by simply using a real keystore instead of the debug keystore (I know I should have tested that earlier, but I thought there would be no difference and the debug keystore would be better for debugging).

So I’m able build and test my App on my device, but the general issue (when usind the debug keystore) remains.

So I don’t know, should I marke this topic as solved (as it is for me, but not in general)?

Don’t mark it as solved. I’ll see if I can get some thoughts from our Android experts on this. But I’m glad you have a work around.

Rob

Are there any errors in the console log?

What version of Corona is it happening with?

Did you change Corona Versions in the time when this was working and when it doesn’t?

Do you have a lot of “local” variables/functions?

Rob

Hey Rob,

thanks for your reply.

On simulator console I got no errors or warnings. On device I was only able to use an logcat app (as I did not get my device to show up in the adb) which shows no messages as well.

It occurs with current public version ( 2016.2906 ) and several daily builds (tested 2016.2935 - 2016.2938).

I did not change the version before the issue (only afterwards, to check if it was a version issue) and as I said, if remove the function call it works fine in all versions.

Inside the scope the functions are called there are about 30 local variables. (2 declared in the same block, the rest are declared outside, but only 10 of those are used inside the same block).

In the absence of any errors, what is happening? Is the app just exiting?

And the really important question. Are you by any chance using a global named “debug”?

Have you disabled runtime errors in your build.settings?

Nothing I’ve seen points to a stack overflow and that would generate a stack overflow error.  You are limited to 200 locals in a module and 60 upvalues, but both of those generate messages.

And are you on Windows or a Mac?

Rob

It simply says in german:

“Appname” wurde beendet. - which translates too - “Appname” has been terminated.

I do not use a global named “debug” and I haven’t disabled runtime errors in the build.settings. (I also use the debug keystore)

Well, as I wrote I assume it’s a compiler/building thing (because of the shrink of the file size by 3,5MB), so I didn’t mean a stack overflow in the app but in the compiler/building process.

Right now I’m on PC but I will check on Mac tomorrow.

Gretings

Torben

Hey Rob,

thanks for your help again.

The thing is, I was able to bypass the issue by simply using a real keystore instead of the debug keystore (I know I should have tested that earlier, but I thought there would be no difference and the debug keystore would be better for debugging).

So I’m able build and test my App on my device, but the general issue (when usind the debug keystore) remains.

So I don’t know, should I marke this topic as solved (as it is for me, but not in general)?

Don’t mark it as solved. I’ll see if I can get some thoughts from our Android experts on this. But I’m glad you have a work around.

Rob