Posts: 97
Threads: 23
Joined: Jul 2011
Reputation:
0
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.
Any ideas? Thanks and cheers.
Posts: 97
Threads: 23
Joined: Jul 2011
Reputation:
0
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)
... 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.
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
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)?
Posts: 97
Threads: 23
Joined: Jul 2011
Reputation:
0
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.
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
Thanks oblo.
It seems I've reintroduced a bug with --debug-array.
Will fix it ASAP!
Posts: 97
Threads: 23
Joined: Jul 2011
Reputation:
0
Great! I'll pause the code and, in the meanwhile, I'll start to work on the sprites
Cheers
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
11-15-2018, 12:19 AM
(This post was last modified: 08-08-2021, 09:21 AM by boriel.
Edit Reason: Fix url
)
Posts: 97
Threads: 23
Joined: Jul 2011
Reputation:
0
Tried the win32 version and I couldn't reproduce previous errors with the same code, so it looks good
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
Cheers
Posts: 1,770
Threads: 55
Joined: Aug 2019
Reputation:
24
8) Thank for the feedback
|