Bug: Loading Meshes No Longer Works With BMax 1.32

BlitzMax Forums/MiniB3D Module/Bug: Loading Meshes No Longer Works With BMax 1.32

Uncle(Posted 2009) [#1]
Hi All,

It seems like since the new update to BMax that we have a problem loading meshes because the Readbyte method has been changed in Blitzmax 1.32. Please see thread http://www.blitzbasic.com/Community/posts.php?topic=83917#947706 where Mark confirmed this method has been changed. To test it simply try to load the Teapot.B3D model from the sample folders. For me it fails everytime. Does it do the same for everyone else?

Cheers,


Unc


Chaduke(Posted 2009) [#2]
I just started with BlitzMax but I've been using Blitz3D for several years. I installed 1.32 and MinGW, re-compiled everything with no problems.

Simple examples work fine but if I try to load .b3d files I get these errors on two seperate meshes:

Unhandled exception : Error reading from stream
Unhandled exception : Attempt to index array element beyond array length

Both models load fine from Blitz3D.


Uncle(Posted 2009) [#3]
Hi,

Try changing the ReadTag$ method in the TModel.bmx to read :

Function ReadTag$(file:TStream)
	
	Local pos=StreamPos(file)
	
	Local tag$=""
	
	For Local i = 1 To 4
		
		If StreamPos(file) < StreamSize(file) Then
			Local rb = ReadByte(file)
		
			tag:String = tag:String + Chr:String(rb)
		EndIf
		
	Next
		
	SeekStream(file,pos)
	
	Return tag$
	
End Function


I added an additional check during reading the B3D chunk tag name. Now before it reads a byte from the B3D file it checks to ensure we are not reading past the end of the stream. It seems to work with the few models I had here.

Cheers,


Unc


Chaduke(Posted 2009) [#4]
I can confirm that your change fixed it, I converted a Blitz3D project that loads lots of models and everything is working.


ima747(Posted 2009) [#5]
Bump: just upgraded to 1.32 of bmax and installed the 0.52 minib3d from the versions sticky and loading meshes crashed untill I added the sanity check.

you could also use
if not Eof(file) then


instead of

If StreamPos(file) < StreamSize(file) Then


Does the same thing, just a little more readable imo. regardless, thanks Uncle for the fix! this is just a sanity check so shouldn't affect older versions of bmax if simon wants to impliment it...


simonh(Posted 2009) [#6]
Yep thanks Uncle. Will add your fix to the next release.