Hi all,
New user, working my way through some tutorials and such. Posting this here because I'm a noob!
I was reading the tutorial on bitmap fonts by Craig Chipperfield in
Issue 59 of the Newsletter. I took the functions provided, and added them to my project. I am testing with a couple of the fonts provided in the associated bitmap font pack.
Anyway, when I compile, all is okay. When I run, I receive the following error:
Quote: "Runtime Error 5105 - Memblock position outside range at line 313"
That line is part of the TrimBMFont function provided with the tutorial code. I included the function below, and noted the line corresponding to the error. I made no changes to the tutorial code -- just pasted it in!
Function TrimBMfont( FontNo, Size )
`Set up Local variables
Local BlankColumn as integer
Local Alpha as byte
Local Chr as integer
Local Position as integer
Local Memblock1 as integer
`Find unused memblocks
Memblock1 = 1
repeat
inc Memblock1
until memblock exist( Memblock1 ) = 0
`Find the first column of pixels that
`contains a non-transparent pixel
For Chr = 33 to 126
Make Memblock From Image Memblock1, ( FontNo * 255 ) + Chr
for x = 1 to Size
BlankColumn = 1
for y = 1 to Size - 1
if BMchrLeft( FontNo, Chr ) = 0
Position = ( y * Size * 4 ) + ( x * 4 ) + 15
' Error occurs on the following line
Alpha = memblock byte( Memblock1, Position )
if Alpha > 0
BlankColumn = 0
y = Size - 1
endif
endif
next y
if BlankColumn = 0
BMchrLeft( FontNo, Chr ) = x
x = Size + 1
endif
next x
`Repeat from the right
for x = Size - 1 to 1 step - 1
BlankColumn = 1
for y = 1 to Size - 1
if BMchrWidth( FontNo, Chr ) = 0
Position = ( y * Size * 4 ) + ( x * 4 ) + 15
Alpha = memblock byte( Memblock1, Position )
if Alpha > 0
BlankColumn = 0
y = Size
endif
endif
next y
if BlankColumn = 0
BMchrWidth( FontNo, Chr ) = x - BMchrLeft( FontNo, Chr )
x = 0
endif
next x
delete memblock Memblock1
next Chr
`Set the Space character to display a gap
`that is half the Width of the other characters.
`You can change this to suit your needs but
`I think it works well
BMchrLeft( FontNo, 32 ) = 0
BMchrWidth( FontNo, 32 ) = Size / 2
endfunction
As a noob, I don't yet know what a memblock is, or how to troubleshoot. I was wondering if anyone could provide some pointers... I did a forum search on the error message, but didn't find anything helpful.
Thanks!
Andy