Announcement

Collapse
No announcement yet.

bug in to() function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • bug in to() function

    I think I've found a bug in the to() function that occurs in a specific set of circumstances. If I set up a buffer, call 'to(buffer)', then call print("b") then print("a") then print([STR]buffer), I should see 'ab' on the screen. In the circumstances in this example however, the to() redirect doesn't work and I get 'ba' on the screen. This bug shows up when the redirect/buffer calls are in a function called by a timer and a print statement with a pointer reference is called in a loop in the main program. If a pause is added to the loop , the bug goes away.

    HTML Code:
    #platform "uLCD-32PT_GFX2"
    
    func main()
    
    //A variable.
    var val := 5;
    
    //A pointer to the variable
    var ptr;
    ptr := &val;
    
    //Set a timer to call Foo() after 10 seconds.
    sys_SetTimer(TIMER0, 10000);
    sys_SetTimerEvent(TIMER0, Foo);
    
    //This call to Foo() works fine.
    //Displays 'Before - After - '
    Foo();
    
    repeat
    
    txt_MoveCursor(0, 0);
    
    //print from a pointer reference.
    print([DEC]*ptr);
    
    //After this print statement, calls to 'Foo()' from the
    //timer event don't function properly.
    
    //Adding a pause statement here seems to fix the bug
    //but what is going on in the first place?
    //pause(1);
    
    forever
    
    
    endfunc
    
    func Foo()
    
    //Set the cursor position.
    txt_MoveCursor(1, 0);
    
    //A buffer.
    var Buf1;
    Buf1 := mem_AllocZ(18);
    
    //When the bug occurs, this 'to()' function doesn't work. The following
    //'print' statement prints to the screen instead of to the buffer so we
    //see 'After - Before - ' instead of 'Before - After - '.
    to(Buf1);
    print("After - ");
    
    print("Before - ");
    
    print([STR]Buf1);
    
    //Wait a bit so we can see the result.
    pause(5000);
    
    //Release the buffer memory.
    mem_Free(Buf1);
    
    gfx_Cls();
    
    //Reset the timer.
    sys_SetTimer(TIMER0, 10000);
    
    endfunc
    I'm just worried that the 'adding a pause solution' is only masking the problem. Anybody know what's actually going on here?

  • #2
    I can confirm this on a uVGA-II with R25 PmmC. Adding the delay in the main loops does mask the error.
    Also, thinking it might have something to do with the mem Alloc routine, I changed the buffer to first an array, and then to a static array (private), and still get incorrect results.
    When it is static, you can see that the buffer is not getting written to.....

    [hr]#platform "uVGA-II_GFX2"func main()
    //A variable. var val := 5;
    //A pointer to the variable var ptr; ptr := &val;
    //Set a timer to call Foo() after 10 seconds. sys_SetTimer(TIMER0, 10000); sys_SetTimerEvent(TIMER0, Foo);
    //This call to Foo() works fine. //Displays 'Before - After - ' pause(2000); Foo(); pause(1000); Foo(); pause(1000); Foo(); pause(1000); Foo(); // These all work fine......
    repeat txt_MoveCursor(0, 0); //print from a pointer reference. //print([DEC]*ptr); print(val); //Regular print val++; //After this print statement, calls to 'Foo()' from the //timer event don't function properly.
    //Adding a pause statement here seems to fix the bug //but what is going on in the first place? //pause(500); foreverendfunc
    func Foo()
    //Set the cursor position. txt_MoveCursor(1, 0); print(" \n"); print(" \n"); print(" \n"); txt_MoveCursor(1, 0); pause(300); //A buffer. var private Buf1[100]; var private count:=0; //var Buf1; //Buf1 := mem_AllocZ(18);
    //When the bug occurs, this 'to()' function doesn't work. The following //'print' statement prints to the screen instead of to the buffer so we //see 'After - Before - ' instead of 'Before - After - '. to(Buf1); print(count,"After - ");
    print(count,"Before - "); print("\n");
    print([STR]Buf1); count++;
    //Release the buffer memory. //mem_Free(Buf1);
    //Reset the timer. sys_SetTimer(TIMER0, 10000);
    endfunc
    _______________
    Best Regards,
    Howard

    Comment


    • #3
      Ok, I've just found an even simpler case where to() fails. If the to() statement is in a function whose call is placed inside a print statement, then it will fail.

      Code:
      #platform "uLCD-32PT_GFX2"func main()print([STR]Foo());pause(1000);endfuncfunc Foo()//A buffervar Buf1;Buf1 := mem_Alloc(18);//This should write to the buffer//but prints to the screen instead.to(Buf1);print("Hello world" );//Here we can see the buffer is empty.print("\n" );print([HEX]Buf1[0], "\n" );print([HEX]Buf1[1], "\n" );print([HEX]Buf1[2], "\n" );print([HEX]Buf1[3], "\n" );print([HEX]Buf1[4], "\n" );print("\n", [STR]Buf1);pause(3000);mem_Free(Buf1);return("abc" );endfunc
      if Foo() is placed outside of the print, it works fine.

      Comment

      Working...
      X