Author Topic: "IF THEN DEBUG"  (Read 2475 times)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2747
    • View Profile
"IF THEN DEBUG"
« on: 2010-Feb-17 »
This 'bug' is pretty bad, it affects all GLBasic just now, here is an example from the 3D Entity lib, causing programs ONLY to work properly in debug mode.

Here is an example...

Code: (glbasic) [Select]
FUNCTION EntityLoadTexture: filename$
LOCAL t, sx, sy
t = GENSPRITE()
LOADSPRITE filename$, t
GETSPRITESIZE t, sx, sy
IF sx = 0 THEN DEBUG "failed to load: "+filename$+"\n"
RETURN t
ENDFUNCTION

Now, in debug mode, the above code works fine BUT when not in debug mode the DEBUG command is removed, I guess by the pre-compiler and the next line is used for the THEN statemant.

So I think this is compiled actually compiled...

Code: (glbasic) [Select]
FUNCTION EntityLoadTexture: filename$
LOCAL t, sx, sy
t = GENSPRITE()
LOADSPRITE filename$, t
GETSPRITESIZE t, sx, sy
IF sx = 0 THEN RETURN t // Grabbed from next line
ENDFUNCTION

So in debug mode the code works fine and returns a texture ID, when not in debug mode, it never gets to the "RETURN t" and always returns 0.

Another even simpler example...

Code: (glbasic) [Select]
a=a+1
IF a<100 THEN DEBUG "asddasdasd"
PRINT "I'm here!", 0,20

Try these lines with DEBUG on and then with DEBUG off, with off, the PRINT will die in non-debug mode.
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2747
    • View Profile
Re: "IF THEN DEBUG"
« Reply #1 on: 2010-Feb-17 »
I know how to avoid the bug, I have posted about it in the past but its catching other people out, none the less. I personally use the preprocessor to avoid this kind of thing altogether.

At its simplest, it really should not happen, one line merging into another just because you turned off the debugger, this in essence is what should be fixed.

Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

MrTAToad

  • Guest
Re: "IF THEN DEBUG"
« Reply #2 on: 2010-Feb-17 »
Yes, I had run into that a while ago...  =D

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10814
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: "IF THEN DEBUG"
« Reply #3 on: 2010-Feb-18 »
dude, that's a nasty one.
I'll fix it in the next update.