Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Possible array bug in version 1.8.8 (*solved*)
#1
Hi all

I think I've just found a bug in 1.8.8 (or just my Spectrum emulators doesn't work any more); please, look at this piece of code:
Code:
paper 0: border 0: bright 1: ink 7: cls

DIM y as byte

dim testarray(4,2) as byte
print at 0,0; "Creacion de testarray OK";

for y = 0 to 4
    testarray(y,0) = 0
    testarray(y,1) = 1
    testarray(y,2) = 2
next y
print at 1,0; "Inicializacion de testarray OK";

for y = 0 to 4
    print at y+5,0; testarray(y,0);
next y
print at 2,0; "Lectura de valores OK";

If I compile the code without the --debug-array parameter, the code works well; but if the --debug-array parameter is used, the Spectrum can create the "testarray" array, but it can't initialize the arrays values, giving a 3 Subscript wrong, 40:1 error. Array-base is 0, heap-size is 4768 and ORG is 24576, but tried with other values and still fails.
[Image: good.jpg] [Image: errore.jpg]

Any ideas? Thanks and cheers.
Reply
#2
I' ve continued with more tests and definitely there is some problem with two-dimensional arrays. Look at this code:
Code:
paper 0: border 0: ink 7: bright 1: cls
DIM array(10,10) as integer

for y = 1 to 9
    for x = 1 to 9
        array(y,x) = RND*10
        print y; ","; x; " "; array(y,x)
    next x
next y

With 1.8.8 compiler and the --debug-array parameter enabled , code runs until row 2 column 9, no matter what kind of array is defined (BYTE, INTEGER, ULONG, STRING... all of them)
[Image: Capture.jpg]

... BUT if the line "print y; ","; x; " "; array(y,x)" is removed, the code runs well, without errors. I can tell more examples but basically, errors appears only when accessing array data, and never when creating the array or filling it with data.
@Boriel, hope it helps. Cheers.
Reply
#3
This might be expected if 0 index is out of Range. How are you compiling that code (compiler flags)?
Does it also happen If you define the array with (0 to 4)?
Reply
#4
boriel Wrote:This might be expected if 0 index is out of Range. How are you compiling that code (compiler flags)?
Does it also happen If you define the array with (0 to 4)?

This is how it's compiled: zxb.exe "C:\ZXbasic\tests\testarray.bor" -S 25000 -B -a -t -o "C:\ZXbasic\tests\testarray.tap" --debug-array
Sometimes I change the array dimension to start with 1 (SInclair comp) instead 0 with the --array-base=1 parameter but the result is the same, so defining the array (0 to 4) or (1 to 5) doesn't make any difference.
Reply
#5
Thanks oblo.
It seems I've reintroduced a bug with --debug-array.
Will fix it ASAP!
Reply
#6
Great! I'll pause the code and, in the meanwhile, I'll start to work on the sprites Smile

Cheers
Reply
#7
Ok, can you download it from here?

http://boriel.com/files/zxb/zxbasic-zxba...-win32.zip
http://boriel.com/files/zxb/zxbasic-zxba...ta4.tar.gz
http://boriel.com/files/zxb/zxbasic-zxba...-beta4.zip

Try this and tell me, please :roll:
Reply
#8
Tried the win32 version and I couldn't reproduce previous errors with the same code, so it looks good Smile
For instance, this is another piece of code used to test the bug:

Code:
paper 0 : border 0: ink 7: cls

dim y,x,n,m as uinteger

DIM array1d(100) as ubyte
DIM array2d(23,31) as ubyte

for y = 0 to 100
    array1d(y) = y
    ink (rnd*7)+1
    print "y="; y, "array("; y; ")="; array1d(y),
next y

n = 22528
print at 0,0

for y = 0 to 23
    for x = 0 to 31
        array2d(y,x) = n
        n = n + 1
        print "array("; y; ","; x; ")="; array2d(y,x)
    next x
next y

One dimension arrays always breaks if I tried to access third position or further (so 0 and 1 were OK but 2 gives the Out of Range error) and two dimension arrays always breaks if I tried to access four rows positions or further (so 0,0 1,0 2,0 were good, but 3,0 fails) And it doesn't matter if Array Base is changed or the array was defined like array(5 TO 10) In this case, trying to access array(7) gives the error. But now with 1.8.9 beta4, looks like all these errors are gone Big Grin

Cheers
Reply
#9
8) Thank for the feedback
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)