×

Discussion Board

Results 1 to 15 of 15

Hybrid View

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Surat Thani
    Posts
    260

    Asha 311 issue with Graphics.copyArea?

    Hello,

    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:

    Code:
    (removed)
    Am I doing something wrong, is copyArea not supposed to be used in a loop like this?

    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.
    Last edited by TongMuan; 2013-07-28 at 15:08.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Asha 311 issue with Graphics.copyArea?

    Without real Java ME experience, I would assume it is valid use of the API - especially as it works well in general. You may have tapped into some device bug, you may even consider reporting it (http://developer.nokia.com/bugs/)
    Have you seen an Error or an Exception on the way? I wonder what copyArea does internally. An over-simplified implementation may use Image.getRGB+Graphics.drawRGB. For example as it needs a buffer, it is prone to GC glitches if there are any. Bringing down the device is an other level of problems however.

  3. #3
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    686

    Re: Asha 311 issue with Graphics.copyArea?

    @TongMuan: i took your code and run it on my Nokia Asha 311 for around 5 min and nothing crashed.
    From my Java ME experience I also dont see any reason this code would cause a crash, Note that there a difference between the real screen graphics and other graphics object so maybe your problem in your game is with the real screen graphics.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,734

    Re: Asha 311 issue with Graphics.copyArea?

    It may be worth asking here which firmware version you use. I remember someone mentioned a recent (2-3 weeks ago?) firmware update of the 311.

  5. #5
    Registered User
    Join Date
    May 2008
    Location
    Surat Thani
    Posts
    260

    Re: Asha 311 issue with Graphics.copyArea?

    Sorry, should have tested the crashing midlet example code on another 311 before posting, it appears to somewhat depend on device or device state (crashing seems to happen faster if the device has just been rebooted, for example). Yesterday it was quickly and consistently crashing the RDA device I tested with, today the same package didn't crash another device at all, at least not withing around a minute that I waited. However, after changing the sleep time to 10 ms, it now crashed on two different devices every time (always within 30 seconds, usually less than 10), I tried on both three times:

    Nokia Asha 311
    355477058348419
    +358504871623
    SW 05.92

    Nokia Asha 311
    355477058350936
    +358504871644
    SW 05.92

    I will edit the code in the original message, and change the sleep time from 50ms to 10ms, in case someone else wants to try this as well.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

    Re: Asha 311 issue with Graphics.copyArea?

    This should not crash anything. However, if you use while(true)/sleep in Java, you are doing something wrong. Although, this is just a rule of dump, let us start from here. Please, try to explain your (thread/game) logic again, as I did not got it, yet.

  7. #7
    Registered User
    Join Date
    May 2008
    Location
    Surat Thani
    Posts
    260

    Re: Asha 311 issue with Graphics.copyArea?

    Thanks for the reply.

    The CrashMidlet posted is code to just to reproduce the crash as simply as possible, it's not my game code. In the actual game loop, there's of course an exit condition, instead of while(true). Also, doing some sleeping in each run of the loop in a non-ui game thread is recommended in many sources, to make sure the UI thread can run (in case the J2ME implementation's threading is not implemented in a pre-emptive way).

    Not sure how my actual game loop is relevant, as the issue is clearly in Image's Graphics' copyArea function (because this is the only thing CrashMidlet's thread does, and the midlet crashes every time on Asha 311), but my game loop in a thread in a GameCanvas subclass goes as follows:

    while(stop thread not requested)
    1. Scroll and update the background bitmap, as described in the original post
    2. Move objects
    3. Check hits of objects against background and each other, update their status
    4. Draw the new situation to GameCanvas' Graphics
    5. Flush graphics
    6. Sleep

    Pointer and key events are handled in the main UI thread.

Similar Threads

  1. LWUIT TextField issue (Asha FullTouch )
    By bogus40 in forum Mobile Java UI and User Experience
    Replies: 6
    Last Post: 2014-03-21, 08:22
  2. Nokia Asha 501 Emulator - jar size issue
    By Giorg189 in forum Mobile Java Tools & SDKs
    Replies: 4
    Last Post: 2013-07-16, 18:13
  3. 6600 graphics issue
    By ralabate in forum General Development Questions
    Replies: 0
    Last Post: 2004-07-22, 21:18
  4. Graphics.copyArea() vs Image.getRGB() / Graphics.drawRGB() ?
    By akokchai in forum Mobile Java General
    Replies: 1
    Last Post: 2004-06-23, 04:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×