Two bugs: CreatePixmap, LoadGlyph

BlitzMax Forums/BlitzMax Programming/Two bugs: CreatePixmap, LoadGlyph

Vlad(Posted 2006) [#1]
With this code BMax crashes two times.
Function PixmapReDim(src:TPixmap var, w%, h%)
	Local pm:TPixmap = src.Copy()
	src = CreatePixmap(w , h , src.format)
	
	'fill with 0
	Local c:Int = $000000FF
	Local p:Int ptr = Int ptr(src.PixelPtr(0,0))
	Local l = w*h
	For Local i=0 Until l
		p[i]=c
	Next
	
	src.Paste( pm , 0 , 0 )
	'DebugStop
End Function

Function AddChar( dst:TPixmap var, font:TImageFont, char% )
	Local glyph:TImageGlyph = font.LoadGlyph( char )
	Local x% = dst.width
	Local h% = dst.height
	If (glyph._h + glyph._y) > h Then h = glyph._h + glyph._y
	PixmapReDim( dst, x + glyph._w, h )
	dst.Paste( glyph._image.pixmaps[0], x, glyph._y )
	
	'DrawOnImage( dst, glyph._image, x, glyph._y )
End Function

'==============================================================================

Local fontFile$ = GetFontsPath() + "verdana.ttf"
Local font:TImageFont = LoadImageFont( fontFile, 12 )

Local bmp:TPixmap
Local i% = 0
Local mi% = i+255
'------------------------------------------------------------------------------

Local glyph:TImageGlyph = font.LoadGlyph(i)
bmp = CreatePixmap( glyph._w, glyph._h+glyph._y,  PF_RGBA8888, 4 )
bmp.Paste( glyph._image.pixmaps[0], 0,glyph._y )

For i=i+1 To mi
	AddChar( bmp, font, i )
Next

The first bug in
Local glyph:TImageGlyph = font.LoadGlyph(i)
when i from 0 to about 20. These chars must exists!
Change init value from 20 and see second bug.
Local i% = 20

The second bug in the PixmapReDim function in the
src = CreatePixmap(w , h , src.format)
Detailed about: error occured in the module "pixmap.bmx" in the code:
pixmap.Pixels=MemAlloc( capacity )
when char or number of new pixmap is about 103.

WindowsXP Pro SP1, AMD Sempron 2600, 1 GB RAM, Radeon 9550


skidracer(Posted 2006) [#2]
There is no law saying glyphs have to have images, as it is very unlikely for any characters <=32 (space) to be printable in a character set.

You will need to add your own checks such as:



Vlad(Posted 2006) [#3]
Well, tnx for answer. But this not remove problems.
Your command /If Not src Return/ test only existing of pixmap in the src variable. This maked code more safe, but error not in /src.Copy()/ command!!! Variable src is exists!!!
Error in the /src = CreatePixmap(w , h , src.format)/ command! After several (about 100) redims.

And do u know what printable characters in TImageFont class starts from 0 (null)! Or not? Are u is legal team member or I am? Prease make this test with couple of old code, or make your own for see character with code 33:
Local fontFile$ = GetFontsPath() + "verdana.ttf"
Local font:TImageFont = LoadImageFont( fontFile, 12 )

Local bmp:TPixmap
Local i% = 33
Local mi% = i
'------------------------------------------------------------------------------

Local glyph:TImageGlyph = font.LoadGlyph(i)
If glyph and glyph._image
	bmp = CreatePixmap( glyph._w, glyph._h+glyph._y,  PF_RGBA8888, 4 )
	bmp.Paste( glyph._image.pixmaps[0], 0,glyph._y )
Else
	bmp = CreatePixmap( 1, font.height(),  PF_RGBA8888, 4 )
EndIf

For i=i+1 To mi
	AddChar( bmp, font, i )
Next

SavePixmapPNG( bmp, AppDir + "\image1.png" )

This must be "!" char. But result char is "?" with char-code 63!
Why printable chars haven't glyphs?
--
Kings Regards, Vlad.
ps:sorry for my bad english


Vlad(Posted 2006) [#4]
Problem is solved.
The main bug in the graphic initialization. If graphics mode has initialized all works fine. But why if font classes so depend from TGraphics its works independent but uncorrectly?


Dreamora(Posted 2006) [#5]
Loading font creates a texture to use within BM.
BM does not use the TTF for more than generating that file.
BM has no 2D mode, not even for drawing text. Its all 3D.


Vlad(Posted 2006) [#6]
Tnx, Dreamora. I understand it when solved those bugs. My point in the best method will don't create font object (or its glyphs at least) before any initialisation of graphics mode at module level.
font:TImageFont = LoadImageFont("font.ttf", 16)
This code will init the font variable with null. Bu this code:
graphics 640,480,32
font:TImageFont = LoadImageFont("font.ttf", 16)
Will init font variable with properly font object.
But now situation is so strange.
If don't init graphics mode, but create any font object. We can access to the same of glyphs of this font. But some of existing glyphs is unavailable until graphics being initialized.
ps:sorry for my bad english.