IncBin & TStream errors Why?

BlitzMax Forums/BlitzMax Programming/IncBin & TStream errors Why?

GregBUG(Posted 2007) [#1]
Hi!
i have a problem using incbin and using tstream for loading custom data files...

i need to load a .dat file (a simple sequence of int) normally it works fine but if i include the .dat file in main exe width "incbin" the program crash with the message "Attempt to access field or method of null object"

you can reproduce the problem with this litte test.


1. USE THIS TO GENERATE A FILE .DAT

[CODE]
SuperStrict

Global TestArr:Int[9]

For Local j:Int = 0 To 8
TestArr[j] = Rand(0, 1000)
Next

Global s:TStream = WriteStream("test.dat")

For Local j:Int = 0 To 8
Print TestArr[j]
WriteInt(s, testarr[j])
Next

CloseStream(s)
[/CODE]

2. run this and you get the error...

SuperStrict

Incbin "test.dat" 

Global TestArr:Int[9]
Global s:TStream = OpenStream("incbin::test.dat")

For Local j:Int = 0 To 8
	testarr[j] = ReadInt(s)
Next

For Local j:Int = 0 To 8
	Print testarr[j]
Next
CloseStream(s)


Why ? Where is the problem ? inbin don't work with Stream?
it a BMAX Bug ?

help!!!! ;)

Ciao
Gianluca.


tonyg(Posted 2007) [#2]
You can't OpenStream to an incbin file as it means you intend to write to it. Change Openstream to Readstream.


GregBUG(Posted 2007) [#3]
opss.
thanks tonyg

some times i'should read better the DOCS!!!

thanks!!!


Yan(Posted 2007) [#4]
...Or use...
OpenStream("incbin::test.dat", True, False)

..Which is all ReadStream() does anyway.