×

Discussion Board

Results 1 to 11 of 11

Thread: RMS headache!

  1. #1
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Series 40 Reboots!!

    I'm starting to hate the letters RMS.

    I can now reliably reproduce on of my problems with RMS. The following code creates and deletes records at random. After about five runs, the phone (Nokia 6100) does some kind of reboot. The MIDlet will then not run again - it will reboot the phone each time. Sometimes this is preceded by the following error:

    RecordStoreException: error closing .db file

    but usually there is no exception before hand. Once I had:

    RecordStoreException: ALLOC ERR 114 is not a free block!

    but I think that may be a different situation.

    Is this a bug in RMS???

    (how can I post code here without losing the tabs?)

    import java.util.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.rms.*;

    public class RMStest
    extends MIDlet
    implements CommandListener, Runnable
    {

    private static final Command cmdEXIT = new Command ("Exit", Command.EXIT, 1);

    private Display m_disp;
    private Thread m_thd;
    private Form m_frm;

    public void startApp () {
    m_disp = Display.getDisplay (this);

    if (m_frm == null) {
    m_frm = new Form ("RMStest");
    m_frm.append ("Working...");
    m_frm.addCommand (cmdEXIT);
    m_frm.setCommandListener (this);
    }

    m_thd = null;
    m_disp.setCurrent (m_frm);
    m_disp.callSerially (this);
    }

    public void pauseApp () {
    m_thd = null;
    }

    public void destroyApp (boolean bUnconditional) {
    }

    public void run () {
    if (m_thd == null) {
    m_thd = new Thread (this);
    m_thd.start ();
    return;
    }

    StringBuffer buf = new StringBuffer (4100);
    int nBigSize = 2000 + random (2000);
    while (buf.length () < nBigSize) {
    buf.append ("ABCDEFGH");
    }
    byte [] aoBigRecord = buf.toString ().getBytes ();

    buf.setLength (0);
    int nSmallSize = 100 + random (1000);
    while (buf.length () < nSmallSize) {
    buf.append ("ABCDEFGH");
    }
    byte [] aoSmallRecord = buf.toString ().getBytes ();

    buf = null;

    try {
    int nCount = random (5) + 1;

    Vector vecIndex = Record.getIndex ();
    for (int i = 0; i < nCount; i ++) {
    if (vecIndex.size () > 0) {
    int j = random (vecIndex.size ());

    Record rec = (Record) vecIndex.elementAt (j);
    vecIndex.removeElementAt (j);
    rec.delete ();
    }
    m_frm.append ("[-]");
    }

    for (int i = 0; i < nCount; i ++) {
    byte [] ao;
    if (random (2) == 0) {
    ao = aoBigRecord;
    }
    else {
    ao = aoSmallRecord;
    }
    new Record (ao);
    m_frm.append ("[+" + ao.length + "]");
    }

    m_frm.append ("Done.");
    }
    catch (Exception e) {
    m_frm.append (new StringItem ("Error", e.toString ()));
    }
    }

    public void commandAction (Command cmd, Displayable disp) {
    if (cmd == cmdEXIT) {
    m_thd = null;
    destroyApp (false);
    notifyDestroyed ();
    }
    }

    private Random m_rnd;
    private int random (int nMaxPlusOne) {
    if (m_rnd == null) {
    m_rnd = new Random ();
    }
    int n = m_rnd.nextInt ();
    if (n < 0) {
    n = -n;
    }
    return n % nMaxPlusOne;
    }

    private static class Record {

    private static RecordStore ms_rs;

    private static void open () throws RecordStoreException {
    if (ms_rs == null) {
    ms_rs = RecordStore.openRecordStore ("store", true);
    }
    }

    private static void close () throws RecordStoreException {
    if (ms_rs != null) {
    ms_rs.closeRecordStore ();
    ms_rs = null;
    }
    }

    public static Vector getIndex () throws RecordStoreException {
    Vector vecIndex;
    open ();

    vecIndex = new Vector (ms_rs.getNumRecords ());
    int nLimit = ms_rs.getNextRecordID ();
    for (int i = 1; i < nLimit; i += 2) {
    try {
    vecIndex.addElement (new Record (i));
    }
    catch (InvalidRecordIDException e) {
    // record deleted
    }
    }
    return vecIndex;
    }

    private int m_nRecord;

    public Record (byte [] ao) throws RecordStoreException {
    open ();
    try {
    if (ms_rs.getNextRecordID () % 2 == 0) {
    ms_rs.addRecord (null, 0, 0);
    }
    m_nRecord = ms_rs.addRecord ("fish heads".getBytes (), 0, 10);
    ms_rs.addRecord (ao, 0, ao.length);
    }
    finally {
    close ();
    }
    }

    private Record (int nRecord) throws RecordStoreException {
    open ();
    // check that record exists (throw InvalidRecordIDException if not)
    ms_rs.getRecord (nRecord);
    m_nRecord = nRecord;
    }

    public void delete () throws RecordStoreException {
    open ();

    try {
    ms_rs.deleteRecord (m_nRecord);
    ms_rs.deleteRecord (m_nRecord + 1);
    }
    finally {
    close ();
    }
    }
    }
    }
    Last edited by grahamhughes; 2003-07-28 at 11:31.

  2. #2
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    75
    my development also facing reboot problem, mine 1 is String object over. i m using Nokia 6800 (Serie 40)

    "drawString("" + (int)a,0,0,g.TOP|g.HCENTER);"
    "drawString(Integer.toString((int)a),0,0,g.TOP|g.HCENTER);"

    this 2 line make my hand phone reboot.

    my emulator show no object created, free memory didnt drop but maintain, but in the real phone, it still reboot.

    i know this is a heap problem, is "repaint()", "drawImage" also create object to make heap increase??? anybody HELP ???

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    In the code I've given, I open and close the RecordStore around each update... this is because if I don't, I have experienced deletes not freeing any space - even though the record has been deleted. But: doing all the opens and closes seems to make the reboot problem worse. Of course, I am creating and destroying more RecordStore objects, so perhaps it is a memory allocation issue.

    Regarding your problem: are you able to use drawString() in the same code with a String? What type is 'a' before you coerce it to an int? Does it behave differently if 'a' is declared as an int? What if you change the coordinates or alignment?

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    fabiolee,

    I am trying to report these problems as bugs to Nokia. There seems to be a variety of RMS-related problems, and your reboot problem may well be related to mine. There is no way we should be able to write Java code that results in a reboot - that's the whole point of running in the sandbox. So these are VM bugs of some kind.

    By the number of question marks and capital-letters you've used, I'm guessing this problem is a potential show-stopper for you... and it's the same for me (unless I find some magic). So we really need some information form Nokia.

    This is cropping up on the "Java Enabled Phones" board, under a thread about 7210 record deletes. I'll let you know what response I get.

    Cheers,
    Graham.

  5. #5
    Regular Contributor
    Join Date
    Mar 2003
    Location
    USA
    Posts
    90

    no bug in RMS

    Grahamhughes

    no bug in rms however you have several errors in your rms code..

    Sorry I don't have time to elaborate further at the moment..


    See Nokia articles on RMS for further details..

  6. #6
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    75
    actually my code is like this:

    int a = 0;
    boolean go = true;

    public void paint(Graphics g){
    drawString("" + a,0,0,g.TOP|g.HCENTER);
    }

    public void run(){
    while (go){
    a++;
    }
    }

    no matter i use "drawString("" + a,0,0,g.TOP|g.HCENTER);" or "drawString(Integer.toString(a),0,0,g.TOP|g.HCENTER);" also create a lot of "String object" and "String Buffer object".

    i m writing a game, if "a" as a "score", then i will be not able to write my game as i cannot show "score" on the screen since "drawString("" + a,0,0,g.TOP|g.HCENTER);" cannot use. is this Nokia 6800 bug?

    any other game developer can help me on how to add score and display it on the screen by no error(no heap problem happen)???

  7. #7
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    fabiolee,

    I should warn you... I haven't tried this...

    private char [] achScore = new char [20];
    private int iScoreStart;

    public void setScore (int nScore) {
    int i = achScore.length;
    do {
    i --;
    achScore [i] = (char)('0' + (nScore % 10));
    nScore /= 10;
    } while (i > 0 && nScore > 0);
    iScoreStart = i;
    }

    public void paint (Graphics g) {
    g.drawChars (achScore, iScoreStart, achScore.length - iScoreStart, 0, 0, g.TOP|g.HCENTER);
    }

    At the very least... it shouldn't create any garbage Strings.

    Hope it helps you.

    Graham.

  8. #8
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    75
    i have try ur code like this:

    import javax.microedition.lcdui.*;
    import java.io.IOException;

    public class DebugCanvas extends Canvas implements Runnable {
    private boolean go;
    public static final Font font = Font.getFont( Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
    private char [] achScore = new char [6];
    private int iScoreStart;
    private int dw, dh;

    public DebugCanvas() {
    dw = getWidth();
    dh = getHeight();
    }

    public void setScore (int Score) {
    int i = achScore.length;
    do {
    i--;
    achScore[i] = (char)('0' + Score % 10);
    Score /= 10;
    } while (i > 0 && Score > 0);
    iScoreStart = i;
    }

    public void paint(Graphics g) {
    g.setColor(0xffffff);
    g.fillRect(0, 0, dw, dh);
    g.setFont(font);
    g.setColor(0x000000);
    setScore((int)Runtime.getRuntime().freeMemory());
    g.drawChars (achScore, iScoreStart, achScore.length - iScoreStart, dw / 2, dh / 2, Graphics.TOP | Graphics.HCENTER);
    }

    public void start() {
    go = true;
    Thread t = new Thread(this);
    t.start();
    }

    public void stop() {
    go = false;
    }

    public void run() {
    int timeStep = 80;
    while (go) {
    long start = System.currentTimeMillis();
    repaint();
    long end = System.currentTimeMillis();
    int duration = (int) (end - start);
    if (duration < timeStep) {
    try { Thread.sleep(timeStep - duration); }
    catch (InterruptedException ie) { }
    }
    }
    }
    }

    i try to show free memory out to the hand phone screen but the free memory is dropping, i didnt create any object else, only "drawChars", anybody help??? i want to show free memory out but remain memory by didnt create any object, thank u for anybody help!

  9. #9
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    I'm afraid you can't avoid creating garbage altogether... a new Graphics object is created for each paint() invokation, which becomes garbage as soon as paint() completes.

  10. #10
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    75
    the code above i test it on both "j2me toolkit default emulator" and "Nokia Serie 40 emulator", i found out that the free memory on "j2me toolkit default emulator" didnt decrease, but in "Nokia Serie 40 emulator" the free memory is dropping, i also test it on "Real Nokia 6800 hand phone" and "Nokia Serie 60 emulator", it also dropping, is NOKIA handphone has bug on it??? y "j2me toolkit default emulator" didnt have this problem???

  11. #11
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    75
    private char [] achScore = new char [20];
    private int iScoreStart;

    public void setScore (int nScore) {
    int i = achScore.length;
    do {
    i --;
    achScore [i] = (char)('0' + (nScore % 10));
    nScore /= 10;
    } while (i > 0 && nScore > 0);
    iScoreStart = i;
    }

    public void paint (Graphics g) {
    g.drawChars (achScore, iScoreStart, achScore.length - iScoreStart, 0, 0, g.TOP|g.HCENTER);
    }

    this code is useful, it didnt create any object at all, is good for games developer to display games score on the hand phone screen.

Posting Permissions

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