I have a very peculiar issue that I'm running into. This is, frankly, the most intractable bug I've run into for years.
The code here is VERY simple and fundamental, therefore it can't be a bug in Blitz. It has to be something that I'm not seeing.
This is an 8x8x8 cubical array. I am attempting to set each cell of the array with a different value. However, when I later read the cells, they all come out the same as the last value that I fed in! In other words, ALL THE CELLS ARE APPARENTLY OVERWRITTEN WITH THE SAME VALUE.
The strangest thing is that the error happened with Blitz's built-in multidimensional array functionality. So I thought that it might be a bug with that, and I wrote my own array class using a 1d array, with aliasing to make it 3d thus:
data_array[x+(8*y)+(64*z)].r=x+y+z
Trouble is that the same error occurs!
I have done my best to pare away everything that is not necessary to isolate the bug, but I still can't see where the problem lies. Might anyone have any idea? I am afraid that there may be some sort of bug in the Blitzmax functionality for arrays of types....!?!?!
Initially things weren't packaged away in classes but were all procedural. Imagine my horror after I wrote my own array class, packaged away in classes, and the same error occurred with different code!
Am I going insane? Sure feels that way.
SuperStrict
'jgrid is an 8x8x8 grid of Tcolor types. For testing purposes, just looking at the r value-- same problem occurs with g and b so removed them.
Type Tcolor
Field r:Double
End Type
Type Jgrid
Field data_array:tcolor[512]
Field tempcolor:tcolor = New tcolor
Method set(x:Int,y:Int,z:Int,r:Float,g:Float,b:Float)
data_array[x+(8*y)+(64*z)].r=r
End Method
Method get:tcolor(x:Int,y:Int,z:Int)
Local returnvalue: Tcolor = New Tcolor
returnvalue = data_array[x+(8*y)+(64*z)]
Return returnvalue
End Method
Method randomize()
For Local x:Int = 0 To 7
For Local y:Int = 0 To 7
For Local z:Int = 0 To 7
data_array[x+(8*y)+(64*z)].r=x+y+z 'SHOULD THIS NOT ASSIGN EVERY ARRAY ELEMENT WITH A DIFFERENT VALUE!?
Next
Next
Next
End Method
End Type
' Here is the testing driver for the above classes.
Global testjgrid:jgrid=New jgrid
testjgrid.randomize()
Local testcolor:tcolor = New tcolor
testcolor = testjgrid.get (3,3,3)
Print testcolor.r
testcolor = testjgrid.get (7,7,7)
Print testcolor.r