Why does my game crash only on Android?

It’s not happy that there are a bunch of empty splines in the level, but I don’t know if that’s making it crash. It looks like the info we need could be in the crash log from the phone – a dump/trace file. Can you find that and post it too?

Hello! I have been working on a 2D tower defense game lately. I finished it, I tested it on Windows, works great, no problems. I installed it on my phone to try it out but every single time when you get by the end of wave 7 it freezes up. I already tried using monitor.bat to find the issue but with no success.

Can anybody please help me out? I already checked my code for null pointers or pointers that get garbage collected. (I marked them with UPROPERTY() )

Here are the logs, I hope you can point me in the right direction: log.txt

That is not causing the crash. The points are added in the editor and the spline mesh for each point during the construction script. I doubt the splines are causing the script but I will check them again…as for the dump /trace file, you mean this one right? It is from Internal Storage/UE4Game/GloomsTD/GloomsTD/Saved/Logs/ GloomsTD.log

I have it now. I could not upload it here so I used OneDrive: Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.

That’s the same UE4 log file. You want the “logcat” log with stack trace.

That’s got everything in it. It would be easier to figure out what’s happening if it was just the logs related to your app. There should be a way to specify to logcat what it will record. I did try to look past all the red herrings but it’s hard to tell which is which. Let’s try to figure it out though (in my answer attempt below).

The only thing I found that is related to your app and could be a problem is line 27706:

linker  : /mnt/asec/com.ArmainAP.GloomsTD-1/lib/arm/libOVRPlugin.so: is missing DT_SONAME will use basename as a replacement: "libOVRPlugin.so"

I don’t see it crashing though so it may find that DLL. But that’s a good place to start I suppose. If this isn’t the problem, you could figure out how to get Android logs that are as deep as possible for your app but exclude everything else, it may help.

Aren’t you asking for the first log I posted? That is the log filtered by monitor.bat using the UE4|Debug filter.

No. That is coming from your game process, so if it crashes it can’t write into the log anymore. We want the log that kicks in after your game process dies or is killed. The thing is, I don’t see that happening in the logtrace but there’s every system event on your phone in there too so it’s hard to tell. You want to filter that log so there’s less extraneous information in it.

The weird thing is it’s running fine until wave 7, right? So unless your game does something special at wave 7, the most likely thing is it’s running out of memory. I saw the android log mentioned “OOM” killing a proc but it didn’t look like it was killing your proc. Still, it could be your issue. On PC you’d need to get to a much higher wave to see the problem. Can you try to build your game so it goes to wave 6, closes and reopens the level and goes to wave 6 again? If that works then it would mean you’re not letting go of actor references. You could also run it on PC and watch its memory usage over a few dozen levels. If this is the problem then it would never go back down.

It looks like all you need is in here Logcat command-line tool  |  Android Studio  |  Android Developers

Turns out that I actually have a memory leak and I know why too. According with this article I should call Destroy() and ConditionalBeginDestroy(). I am calling only Destroy right now. I will update my code and hope it gets fixed! Thank you very much!

I have never seen that before. If it doesn’t work out we can keep trying, but I’ll keep my fingers crossed.

It did not work. But in case any poor soul wanders to this post in the future and reads my comment, please don’t call ConditionalBeginDestroy() inside AActor::Destroyed()

But you did find that it’s not letting go of memory? If so, we can still try to figure out why.

It is weird. I tried your experiment to reset it after wave 6 and it turns out I can reset it without crashing. Turns out the small increase in memory was actually just because the greater ammount of actor I handle each wave.

If the next wave doesn’t start until the previous one is over then you should be able to get your actor count back to baseline at the end of each wave (other than GC hanging on to things itself). But by wave 7 the GC should have cleaned things up enough so it must be that you’re not destroying something.

Idea: set up a test where your enemies commit suicide after a few seconds – so the waves go by really quickly. Run it on PC and watch the memory usage. Make sure it’s a legit leak.

EDIT: Oh you mean just because instead of 10 you have 20 enemies it’s too much?

I mean that is the reason of slight memory increase. This is how I generate the number of enemies per wave with a slight difference that I start from 20 instead of 2.
I am trying now to make them commit suicide.
EDIT: Here is my memory usage:

  • Main Menu 634.2MB constant.
  • In game before to start wave 1 and constantly shooting (bullets get destroyed when they reach the edge of the screen) 651MB with a slight increase of 0.2-0.3 MB every 10 seconds or so.
  • In game after restarting from wave 6 to wave 1: 669.5MB and it remains constant.

I think this is the ultimate proof that I leak memory.

If that’s the case then when you start wave 1 with that too-many number of enemies it should crash from the beginning. Otherwise it’s an accumulation over the waves that uses up the memory.

At this point I barely understand why it does not crash if I restart the level but crashes if I keep playing it beyond Wave 7. How to free up that accumulation?