I'm developing a simple game for J2ME. In game loop thread it uses an offscreen bitmap (Image) for the scrolling background, always first moving the current contents of the bitmap a pixel or a few to the left, then drawing newly visible parts to the right side of the bitmap. In the end of the loop, everything is drawn to the screen via Graphics obtained by GameCanvas.getGraphics() - the background bitmap is drawn first, and then other stuff on top of that.
This works fine on all the emulators that I have, Asha 310, Nokia 808 and Nokia N81. However, I sent the game to a friend who uses Asha 311, and he complained it crashes the whole device so badly that the battery needs to be removed. I checked on on RDA, and was able to narrow the issue to a copyArea call done to the Graphics object of the background bitmap. The following midlet reproduces the issue after running for a while, even without having a Drawable on screen:
Am I doing something wrong, is copyArea not supposed to be used in a loop like this?Code:(removed)
It's pretty easy to change my code so that instead of scrolling the background bitmap, I'll just draw each new vertical line to the right side of the line drawn last time (jumping back to the left side when running out of space) and then draw the background bitmap to the screen in two parts. This is probably more efficient too. However, would be interesting to know if I'm not supposed to do what I'm doing in the code snippet above, and if anyone else has encountered this issue. According to download stats 311 is one of the more popular S40 devices currently.
Edit: Changed sleep time from 50 ms to 10 ms, to make the crashing more consistent.
Edit: Removed code, see later in this thread for the updated version.