Copybank range : Illegal in debug, Fine in release

Archives Forums/BlitzMax Bug Reports/Copybank range : Illegal in debug, Fine in release

BlitzProg(Posted 2011) [#1]
EDIT: not a glitch, only me having been silly
my bad. I forgot that the return value of Resize bank would also be increased by 1. Problem solved

================
Original message

Note: Version 1.41. Maybe i'm out of date... :)

This very nice function allow me to insert a byte inside a bank.

'insertbyte : insert a byte into bank.
'example: bank{ABCD} + insertbyte(bank,2,x) = bank{ABxCD}
Function insertbyte(in:TBank,pos:Int,value:Byte)
	ResizeBank(in,BankSize(in)+1) 'add one byte.
	CopyBank(in,pos,in,pos+1,(BankSize(in)-pos)) 'make space
	PokeByte(in,pos,value) 'put the byte :D
End Function

Local bank:TBank=CreateBank(4)
PokeInt bank,0,$12345678 'insert bytes $78,$56,$34 and $12 all at once

insertbyte(bank,2,$FF) 'put $FF in the middle

For i=0 To BankSize(bank)-1
	Print Right(Hex(PeekByte(bank,i)),2) 'show the contents!
Next 


You get this in release mode, just as expected

78
56
FF
34
12

Turn debug on and you'll get an unhandled exception : Illegal range for CopyBank. :(

Last edited 2011


Zeke(Posted 2011) [#2]
CopyBank(in,pos,in,pos+1,(BankSize(in)-pos-1)) 'make space



BlitzProg(Posted 2011) [#3]
aargh *dies*

ok, then why is release version working? am I risking a memory leak?
Edit: okay, tried with something like +100 and i'm realising there is nothing at all to prevent memory erasing inside the program, only windows detects it as invalid "memory can't be 'read'" - so if there is a place of memory available next to the bank, it will overflow to it or just crash.

Last edited 2011