Forum
Intermittent errors - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16)
+---- Thread: Intermittent errors (/showthread.php?tid=2548)



Intermittent errors - zarsoft - 03-12-2024

I have a subroutine that works well most of the time but sometimes gives an error.
Once every few hundred iterations it gives an error.
I tried changing the mathematical expression but it continues to give errors - sometimes in the old expression, other times in the new expression.
Intermittent errors also occur on other lines of this routine.
I tried changing the type of variables but it also gave errors.
Am I doing something wrong or is the compiler wrong?
If I delete most of the program the intermittent error may continue to appear or may stop appearing.

Does anyone have any idea what could be causing this?

Simplified routine:
Code:
SUB print_sprite (x0 AS LONG, y0 AS LONG)
DIM x,y AS LONG
DIM Width,Height AS LONG
DIM xold AS LONG

LET xold=x0-INT(SPRITES(ix_SpriteWidth)/2)

LET Width=SPRITES(ix_SpriteWidth)
LET x=x0-INT(Width/2)

IF x<>xold THEN PRINT AT 10,10;" xold=";xold;" x=";x: PAUSE 0
END SUB


LET SPRITES(ix_SpriteWidth) = 8

print_sprite(236,46)
' sometimes printout is
xold=232 x=236
'x in error

print_sprite(84,90)
' sometimes printout is
xold=84 x=80
'xold in error