We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey all!
I recently coded a game on Processing Android. It is riddled with animated objects and arraylists of them. It seems to run smoothly on my Samsung Galaxy J3, but when ran on an old Samsung tablet, the game crashes. I have narrowed down the reason to all the arraylists - if I set them to only 2-3 objects each, it is still laggy, but it doesn't crash. If I add more, it crashes after a few seconds.
I am using a P2D render for all of the game. Could that be an issue? Do I need a JAVA2D render for the calculations?
Answers
It is hard to say what is causing the problem. Could be the version of Android you are using, the version of Android Mode in Processing or the design of your app. So many things we don't know. What could help in this case is to provide a MCVE (https://stackoverflow.com/help/mcve) and take it from there.
Why do you say is could be the renderer? If you change the renderer to JAVA2D, does it solve the problem?
Kf
This is a series of snippets from the game's code. //......// signifies a chunk of code has been removed there. I have tried to filter out the likely factors for the game's slowness.
Does anybody see anything amiss in this code?
Sounds like it could be an out of memory error. What is the available heap memory on the tablet compared to the J3?
One way to test this would be to edit the manifest to set a large heapsize.
you are loading a new set of images for each red and white cell. you only need one copy of each. they don't need their own copies of the image, just am index into a shared global copy.
i think generally you have too many images. and that's using too much memory, causing the crash.
in fact you define arrays for the two animations in lines 8 and 10 and then don't use them.
we can't run your 383 lines of code without the 70 images.
@koogs Damn, you are right. I don't even use those arraylists.
How do I use one copy for each red and white cell? Do I need separate arraylists for the red and for the white cells?
This is what I tried, and I tried using the image arrays that I didnt use previously in the arraylist's argument but I get black squares instead of images.
Can't see anything immediately wrong with the snippet you posted (but obviously don't have all your changes or any of the images...)
Using camelCase for your variable names would aid readability.
What's this doing?
@koogs I'm sorry, but I can't share the images due to obvious risks of them being stolen by somebody. I spent hours upon hours creating the animations, I'm definitely not posting them as royalty free material in a public forum.
I've tried using camelCase, but it really slows down my coding process. Literally half of the time I spend writing code is spent double and triple checking whether capitalization is accurate, and I still overlook some letters resulting in hours of headbanging over a capital letter. It's just not my thing.
Every score object moves left and right within a random "span" - some cover the whole screen, some mere centimeters. That span is randomized for each cell, that is what constrainx is.
I have revisited my code with a fresh mind today and I made it work by only initializing the arrays once in setup. I don't have my tablet handy right now to retry it, but I will keep everyone posted once I find out if it runs better.
Thanks a lot for the help!
I can confirm that this was the reason.
Cheers!
You missed my point with this. How can x be greater than x + something? Only if the something is negative. So a better test would be if (constrainx < 0)
(Spaces between operators makes code more readable)
Ah, yes, how clumsy.
The reason for the error is that I was using vectors first, and the initial position of the object was x, so the function would go something like if(vector.x > x+constrainx) {...
Thanks, I have fixed it now.