BMK in an infinite loop compiling this module

BlitzMax Forums/BlitzMax Beginners Area/BMK in an infinite loop compiling this module

This module, placed in \mods\hot.mod\iff8svxloader.mod\iff8svxloader.bmx:
Strict

Rem
bbdoc: IFF8SVX loader
End Rem

Module HOT.IFF8SVXLoader
ModuleInfo "Version: 1.00"
ModuleInfo "Author: Hotcakes"
ModuleInfo "License: Public Domain"
ModuleInfo "Copyright: Toby Zuijdveld"
ModuleInfo "Favourite Food: Pizza"

Import BRL.AudioSample
Import BRL.EndianStream

'Import BRL.Blitz
'Import BRL.Retro

Private

Function ReadTag$( stream:TStream )
	Local tag:Byte[4]
	If stream.ReadBytes( tag,4 )<>4 Return
	Return Chr(tag[0])+Chr(tag[1])+Chr(tag[2])+Chr(tag[3])
End Function	' Stolen from Blitz Research

Function SkipBytes(stream:TStream,count)
	stream.skipbytes(count)
End Function	' This function wrapper is missing ;]

Public

Type TAudioSampleLoaderIFF8SVX Extends TAudioSampleLoader

	Method LoadAudioSample:TAudioSample( stream:TStream )
		stream=BigEndianStream(stream)				' Motorola induced endianivity

		If ReadTag( stream )<>"FORM" Then Return	' Not an IFF file
		Local w_len=Readint(stream)
		If w_len+8>StreamSize(stream)
			If StreamSize(stream)>-1 Then Return	' Truncated file 
		EndIf

		If ReadTag( stream )<>"8SVX" Then Return	' Not an 8SVX file

		If ReadTag( stream )<>"VHDR" Then Return	' Compulsory field
		ReadLong(stream);ReadLong(stream)			' 4 unimportant Ints
		Local w_hz=ReadShort(stream)
		If ReadByte(stream)>1 Then Return			' Multioctave not supported
		If ReadByte(stream) Then Return				' Compression not supported
		Local w_vol:Float=ReadShort(stream)+(ReadShort(stream)/$10000)	' That...  uhhh...  might work...
				'	It's supposed to be a 16bit.16bit floating point value, but I never understood floating point
		Repeat	'		numbers =] Anyway, it's a volume adjustment value, which we'll be using later...
			If readtag(stream)="BODY" Then Exit		' That's what we're looking for
			skipbytes stream,Readint(stream)		' Skip the useless info stuff and, yes.  Well, I'm rambling.
		Forever	' Forever
		
		w_len=Readint(stream)						' Length of the sample
		Local t:TAudioSample=TAudioSample.create(w_len,w_hz,SF_MONO8)
		Local buf:Byte Ptr=t.samples
		For Local i=0 To w_len	' Probably a cleaner way to do this, but I don't know it =]
			Local w_tmp=ReadByte(stream)
			If w_tmp>127 Then w_tmp:-128 Else w_tmp:+128	' Signed-->Unsigned
			buf:+w_tmp
		Next	' i=0 To w_len
'		stream.readbytes t.samples,w_len

		Return t									' Good to go.
	End Method

End Type

AddAudioSampleLoader New TAudioSampleLoaderIFF8SVX

Appears to send BMK into an infinite memory consumptious loop ;] I left it running overnight because I just couldn't be bothered anymore and when I woke up in the morning Windows had popped up a low on virtmem error (keep in mind my max virtmem is set at 4gb:) and when I clicked OK to that, BMK promptly crashed. Ha!

So I'd like to know if I'm doing something horribly wrong or if it's a bug. Because I don't know any better.

It was compiling fine, before I put the For Local i=0 To... loop in. It used to just be the stream.readbytes command and that worked AOK. But I can't see anything wrong with the loop. It said in the docs that you can define a Local like that (in a For line) and I have Strict on so bmk will probably complain if I didn't... still... I don't see anything else that could be remotely classified as wrong. Help! =]

Well... It's not BMK that's eating the mem... It's bcc.exe. But you are right. It'll gladly sit and spin. I changed the declare to be outside that loop and that isn't it.

Still looking........

Kanati

[EDIT #1]
Ow ow ow ow... sometimes even when the compile returns an error and you think everything is fine, bcc.exe sits and burns memory. And will sometimes hold on to the file.bmx.s file so successive compiles will return an error saying it couldn't find the file. I just had to clear out 5 running bcc.exe processes.

[EDIT #2]
Well this is your problem line:

		ReadLong(stream);ReadLong(stream)			' 4 unimportant Ints


Readlong is a function and returns a long... Obviously. But if you use it like you are, it blows the crap out of the compiler, sending it into a rainman-esque autistic rage. Change it to:

		Local l1:Long = ReadLong(stream);l1 = ReadLong(stream)			' 4 unimportant Ints


And it compiles fine. Definitely a bug in the compiler. At worst it should cause a syntax error in the compile.

Ow ow ow ow... sometimes even when the compile returns an error and you think everything is fine, bcc.exe sits and burns memory. And will sometimes hold on to the file.bmx.s file so successive compiles will return an error saying it couldn't find the file. I just had to clear out 5 running bcc.exe processes.

Wow. I didn't get that one yet =]

And it compiles fine. Definitely a bug in the compiler. At worst it should cause a syntax error in the compile.

OK, Well blow me down and call me Charlie. I guess Max doesn't handle stack screwups as elegantly as B3D did ;] In previous Blitz's, as you no doubt know, you could call a function, not collect the result and have it discarded nicely.

Really strange thing is that if you take out all the Local definitions after t:TAudioSample, the code works and compiles 100% fine - but -one- more and the compiler goes haywire. Looks like I just pushed it over the edge.

Thanks for your help K, I would -never- have thought of that!