Problem with NG and fields in types

BlitzMax Forums/BlitzMax NG/Problem with NG and fields in types

rs22(Posted 2016) [#1]
Hi,

When running my game as 64-bit, I'm having trouble with the values of fields in my types being changed for no reason. This doesn't happen with normal BlitzMax or in 32-bit mode with NG.

I've tried to recreate what I'm doing with the code below. With this code, in 64-bit mode, it prints out 5 and 1. In 32-bit mode, it always prints 5, as it should. Am I doing something wrong?
Type MyType
	Field a:Int = 0
EndType

Type MyArrayType
	Field test:MyType[0,0]
EndType

Global d:MyArrayType = New MyArrayType
d.test[,] = New MyType[50,50]

For Local x:Int = 0 To 49
	For Local y:Int = 0 To 49
	d.test[x,y] = New MyType
	d.test[x,y].a = 5
	Next
Next

Graphics 640, 480

Repeat

	For Local x:Int = 0 To 49
		For Local y:Int = 0 To 49
			Local test:MyType = d.test[x,y]
			Print test.a
		Next
	Next

Until KeyHit(KEY_ESCAPE) Or AppTerminate()



Derron(Posted 2016) [#2]
Sounds more like an issue with multi-dimensional arrays (and NG) than a generic "fields in types"-issue.


I tried it on my - a bit dated - NG setup (begin of july) and it only printed "5"...


Is there a reason for you to "loop" over the two for-loops ? I stopped after 5 million prints ;-)

If it really is connected to the iterations of the "repeat", you might think of doing a "if test.a<>5 then print test.a".



bye
Ron


rs22(Posted 2016) [#3]
The two for-loops are for looping through the tiles of a tilemap. The 'a' field would be the tile index.

'a' could be any number based on the number of tiles in the tileset...I could check to make sure it is within the bounds of the tileset indexes, but I'd rather it not be randomly changed like it is now. As I said, it works fine in both 32-bit NG and normal BlitzMax. Only with 64-bit NG does 'a' change to something other than what it is set to by the code.


Derron(Posted 2016) [#4]
I know for which reason the two for-loops exist... I asked for the loop _over_ the two loops: aka the "repeat until".


@ bounds
as you use the same bounds for initialization and also for reading, I doubt that this is the reason of the bug/issue.



Does it only happen when using the array in a type - or does it fail too, when using it directly?


Does it work if you change
d.test[,] = New MyType[50,50]
to
d.test = New MyType[50,50]


bye
Ron


rs22(Posted 2016) [#5]
Well, the Repeat loop is to keep the whole thing running. It needs some kind of loop!

Changing d.test[,] = New MyType[50,50] to d.test = New MyType[50,50] makes no difference.

I have the same problem if the array is Global and not a Field in a type, so I am assuming there is a problem with NG and multidimensional arrays. I should have experimented a little more before deciding on the topic name!


Derron(Posted 2016) [#6]
Well, the Repeat loop is to keep the whole thing running. It needs some kind of loop!


So: it does not happen if only run once?


bye
Ron


rs22(Posted 2016) [#7]
I guess not, but that seems to be an irrelevant point...the screen needs to be updated, so the array is going to be accessed on every loop.


Brucey(Posted 2016) [#8]
Rather than dump out millions of lines...
SuperStrict

Framework brl.standardio
Import brl.glmax2d

Type MyType
     Field a:Int = 0
EndType

Type MyArrayType
     Field test:MyType[0,0]
EndType

Global d:MyArrayType = New MyArrayType
d.test[,] = New MyType[50,50]

For Local x:Int = 0 To 49
     For Local y:Int = 0 To 49
     d.test[x,y] = New MyType
     d.test[x,y].a = 5
     Next
Next

Graphics 800, 700, 0

Repeat

     Cls

     For Local x:Int = 0 To 49
           For Local y:Int = 0 To 49
                Local test:MyType = d.test[x,y]
                Local i:Int = test.a
                DrawText i, x * 14, y * 13
                If i <> 5 Then
                     Print i
                End If
           Next
     Next
     
     Flip

Until KeyHit(KEY_ESCAPE) Or AppTerminate()


I'll have a look at it later.


rs22(Posted 2016) [#9]
Yes, that's better. My sleepless brain didn't consider that, honestly.

Thanks for looking into it!


Brucey(Posted 2016) [#10]
How long should I run it for before I start to see a problem?


I left it running for 40 minutes, and it worked okay.
That's the latest modules/bcc running on Win7 Pro.


Derron(Posted 2016) [#11]
Just to gather all information:

- which OS did you use for compiling?
- some exotic hardware (itanium CPU)?
- did you use most-current BMK, BCC + freshly compiled modules (at least the brl.blitz-things are important here)

- "prints out 5 and 1": please print out
x+","+y+" " + test.a
if it is "<> 5".

Question: does it print on "random" x,y or always the same?


bye
Ron


rs22(Posted 2016) [#12]
I tested it on both Windows 10 and OS X Yosemite. Both show the same problem seconds after starting.

Windows 10 is on an Intel Core i3 CPU and OS X is on an Intel Core i5.

I think it's usually the same.

OS X screenshot

I was using the 0.70 release version of NG. I tried downloading the latest source and compiling it, but I got the following error building the modules:

Compile Error: Type 'iunknown' not found
[.../BlitzMax/mod/maxgui.mod/win32maxguiex.mod/tom.bmx;17;0]
Build Error: failed to compile .../BlitzMax/mod/maxgui.mod/win32maxguiex.mod/tom.bmx



Brucey(Posted 2016) [#13]
I shall try to do a Win32 release at some point this week... (although, with No Man's Sky out tomorrow it may be the weekend before I get some time :-p)

If you want to use the latest bcc, you also will need the latest brl.mod, pub.mod and maxgui.mod (and perhaps any others that you are using from https://github.com/bmx-ng )


rs22(Posted 2016) [#14]
I did download the latest of everything from GitHub. I got that error trying to build it all, though.

I don't mind using the 32-bit version for the time being. Have fun playing No Man's Sky. You probably deserve the time off. :P


Brucey(Posted 2016) [#15]
The latest maxgui ( https://github.com/bmx-ng/maxgui.mod ) on the line indicated in your error above has "IUnknown_" - note the trailing underscore.


col(Posted 2016) [#16]
It might be worth while mentioning that the legacy 'Max and 'MaxNG are 2 separate compilers that each have their own separate module suites.

Some important points...
1. NG specific modules cannot be used with the legacy 'Max compiler.
2. The default legacy 'Max modules cannot be used with the NG compiler.
3. It is easy to write modules that will work with both.

For modules to work with both compilers you have to write your code to do so. It's not difficult and the differences are quite subtle.