FontName corruption?
BlitzPlus Forums/BlitzPlus Beginners Area/FontName corruption?
| ||
My debug log when reaching the UnInitialiseTitleTypeface() function, reports the UI_TIT_GAD_FONT_NAME as the same as Str(UI_TIT_GAD_TYPEFACE) There's no logical reason why this should happen and certainly nowhere in the entire program is UI_TIT_GAD_FONT_NAME set to equal ANYTHING OTHER than the FontName() of a font handle OR A null string. The only thing I can think is that somehow, the actual memory addresses are being affected? Function PickTitleFont() Local NewFont=RequestFont() If (Not(NewFont)) Debug("TITLE (PICK TYPEFACE): Invalid / null selection or request cancelled. No Typeface change applied.") Return End If Debug("TITLE (PICK TYPEFACE): Picked 0x"+Str(NewFont)) Local PickedName$=FontName(NewFont) If (UI_TIT_GAD_TYPEFACE) If (PickedName=UI_TIT_GAD_FONT_NAME) If (FontSize(NewFont)=FontSize(UI_TIT_GAD_TYPEFACE)) If (FontStyle(NewFont)=FontStyle(UI_TIT_GAD_TYPEFACE)) If (FontAscent(NewFont)=FontAscent(UI_TIT_GAD_TYPEFACE)) If (FontDescent(NewFont)=FontDescent(UI_TIT_GAD_TYPEFACE)) FreeFont NewFont Debug("TITLE (PICK TYPEFACE): Selection is identical to current Typeface. No change applied.") Return End If End If End If End If End If Debug("TITLE (PICK TYPEFACE): Plugging memory leaks for previous Typeface 0x"+Str(UI_TIT_GAD_TYPEFACE)) UnInitialiseTitleTypeface End If UI_TIT_GAD_TYPEFACE=NewFont UI_TIT_GAD_FONT_NAME=PickedName UI_TIT_GAD_FONT_FLAGS=GetFontFlags(NewFont) Debug("TITLE (PICK TYPEFACE): Loaded new Typeface "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" Size: "+Str(FontSize(UI_TIT_GAD_TYPEFACE))+" to reference: 0x"+Str(UI_TIT_GAD_TYPEFACE)+" with flags: 0x"+Str(UI_TIT_GAD_FONT_FLAGS)) SetTitle UpdateWYSIWYG End Function Function UnInitialiseTitleTypeface() If (UI_TIT_GAD_TYPEFACE) Debug("INIT (TITLE): Release Typeface Data "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" 0x"+Str(UI_TIT_GAD_TYPEFACE)) UI_TIT_GAD_FONT_NAME="" FreeFont UI_TIT_GAD_TYPEFACE UI_TIT_GAD_TYPEFACE=0 End If End Function DEBUG Output: 11:16:00 | TITLE (PICK TYPEFACE): Picked 0x52211760 11:16:00 | TITLE (PICK TYPEFACE): Plugging memory leaks for previous Typeface 0x52240776 11:16:00 | INIT (TITLE): Release Typeface Data "52240776" 0x52240776 An almost identical couple of functions that deal with a separtate text gadget and its associated font and parameters is below - I never encounter the same issue with this part: Function PickTextFont() Local NewFont=RequestFont() If (Not(NewFont)) Debug("TEXT (PICK TYPEFACE): Invalid / null selection or request cancelled. No typeface change applied.") Return End If Debug("TEXT (PICK TYPEFACE): Picked 0x"+Str(NewFont)) Local PickedName$=FontName(NewFont) If (TEXT_TYPEFACE) If (PickedName=TEXT_FONT_NAME) If (FontSize(NewFont)=FontSize(TEXT_TYPEFACE)) If (FontStyle(NewFont)=FontStyle(TEXT_TYPEFACE)) ;If (FontAscent(NewFont)=FontAscent(TEXT_TYPEFACE)) ; If (FontDescent(NewFont)=FontDescent(TEXT_TYPEFACE)) FreeFont NewFont Debug("TEXT (PICK TYPEFACE): Selection is identical to current Typeface. No change applied.") Return ; End If ;End If End If End If End If Debug("TEXT (PICK TYPEFACE): Plugging memory leaks for previous Typeface 0x"+Str(TEXT_TYPEFACE)) UnInitialiseTextTypeface End If TEXT_TYPEFACE=NewFont TEXT_FONT_NAME=PickedName TEXT_FONT_FLAGS=GetFontFlags(TEXT_TYPEFACE) Debug("TEXT (PICK TYPEFACE): Loaded new Typeface "+Chr(34)+TEXT_FONT_NAME+Chr(34)+" Size: "+Str(FontSize(TEXT_TYPEFACE))+" to reference: 0x"+Str(TEXT_TYPEFACE)+" with flags: 0x"+Str(TEXT_FONT_FLAGS)) UpdateTextParams End Function Function UnInitialiseTextTypeface() If (TEXT_TYPEFACE) Debug("INIT (TEXT): Release Typeface data "+Chr(34)+TEXT_FONT_NAME+Chr(34)+" 0x"+Str(TEXT_TYPEFACE)) FreeFont TEXT_TYPEFACE TEXT_TYPEFACE=0 TEXT_FONT_NAME="" TEXT_FONT_FLAGS=0 End If End Function |
| ||
The mistaken name "52240776" is a font handle converted to a string. Somewhere this was assigned instead of a font name. I would look for places where a value is assigned to UI_TIT_GAD_FONT_NAME and DebugLog that immediately, looking for numbers rather than names. |
| ||
Hi Floyd, thanks for the quick response. I know there was quite a large code block and it may not have been clear enough but I DID mention in the original post that "nowhere in the entire program is UI_TIT_GAD_FONT_NAME set to equal ANYTHING OTHER than the FontName() of a font handle OR A null string." (Incidentally, in case it's not obvious) UI_TIT_GAD_FONT_NAME is of course, a Global string variable |
| ||
Okay, I've found the root point at where the corruption occurs. It was at the point at which a new font is set and text area updated: As you can see I put a few very noticeable checks in: Function SetTitleFont() Debug("TEST::::::::: Current Font: "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" 0x"+Str(UI_TIT_GAD_TYPEFACE)) Local CurrentString$=TextAreaText(UI_TIT_GAD_TEXTBOX) SetTextAreaFont UI_TIT_GAD_TEXTBOX,UI_TIT_GAD_TYPEFACE UI_TIT_GAD_FONT_NAME=FontName(UI_TIT_GAD_TYPEFACE) ;UI_TIT_GAD_FONT_FLAGS=GetFontFlags(UI_TIT_GAD_TYPEFACE) Debug("TEST::::::::: Current Font: "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" 0x"+Str(UI_TIT_GAD_TYPEFACE)) SetTextAreaText UI_TIT_GAD_TEXTBOX,CurrentString Debug("TITLE (SET TYPEFACE): Typeface Set to "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" Size: "+Str(FontSize(UI_TIT_GAD_TYPEFACE))+" to reference: 0x"+Str(UI_TIT_GAD_TYPEFACE)+" with flags: 0x"+Str(UI_TIT_GAD_FONT_FLAGS)) End Function And the resulting debug output: | TITLE (UPDATE): Lock textbox gadget 0x51947360 16:18:03 | TESTING:::::::::::::: FONTNAME Blitz 16:18:03 | TESTING:::::::::::::: FONTNAME Blitz 16:18:03 | TESTING:::::::::::::: FONTNAME ´† 16:18:03 | TITLE (SET TYPEFACE): Typeface Set to "TITLE (SET TYPEFACE): Typeface Set to "68 With Dimens" Size: 27 to reference: 0x51947712 with flags: 0x1 16:18:03 | TESTING:::::::::::::: FONTNAME èª 5ET TYPEFACE): Typeface Set to "TITLE (SET TYPEFACE): Typeface Set to "68 With Dimens 16:18:03 | So you can see something VERY odd is happening here, and I can only suspect it may be something to do with the compiler running in debug mode and the debugging output perhaps eating into some memory that it maybe shouldn't??? Possibly something to do with the memory space for the default 'built-in' Blitz font? |
| ||
Why does debug code say TEST: while the output says TESTING: ? |
| ||
Sorry I was using a separate snippet with duplicate functions to try and reproduce the error, I had posted the wrong snippetr or the wrong output, but it shouldn't make any difference ultimately. It shouldn't matter to the point of the topic because the debug output is just a string that is written to the file. The word "TEST" or "TESTING" is really just that literal and has no bearing on the actual issue. It's quite irrelevant considering the problem is to do with the variable which holds the FontName() value is being 'overwritten' with other data. _ Anyway, there is an element of inconsistency in trying to reproduce the error faithfully. I Have posted a full debug output (until it finally crashed since the Font Handle no longer pointed to a valid object) And the relevant "Title" functions: |
| ||
If you look particularly between:18:14:30 | TITLE (SET TYPEFACE): Typeface Set to "Œ" Size: 10 to reference: 0x46966976 with flags: 0x1 18:14:30 | TITLE (SET COLOUR): Colours set to FOREGROUND: 13717545 BACKGROUND: -1 18:14:30 | TITLE (UPDATE): UnLock textbox gadget 0x46966624 18:14:30 | WYSIWYG (TITLE): Release memory for 0x46930544 18:14:30 | WYSIWYG (TITLE): Image created 0x46931336 With Dimensions: 24 x 15 18:14:30 | WYSIWYG: Updating Display 18:14:30 | TEMPLATE: Drawing Template Front at 487 , 0 Dims: 460 x 648 18:14:30 | TEMPLATE: Drawing Template Rear at 0 , 0 Dims: 460 x 648 18:14:30 | TEMPLATE: Drawing Template Spine at 459 , 0 Dims: 29 x 648 18:14:30 | WYSIWYG (TITLE): Drawing Image at 471.85 , 324.094 18:14:36 | UI (TITLE MENU): FontPicker selected 18:14:49 | TITLE (PICK TYPEFACE): Picked 0x46967392 18:14:49 | TITLE (PICK TYPEFACE): Plugging memory leaks for previous Typeface 0x46966976 18:14:49 | INIT (TITLE): Release Typeface Data "INIT (TITLE): Release Typeface Data "" 0x46966976 Already it is clear that there is something happening to the memory for the variable UI_TIT_GAD_FONT_NAME |
| ||
I apologise for making numerous posts. I didn;t want to edit earlier ones since it may just confuse the issue further due to the logical flow of my investigations. From what I can gather in trying to reproduce the error and narrow down precisely where the issue occurs I think it may be at the point of the "title image update" in which the textbox text is copied onto an image buffer so that it may be rotated and displayed vertically. Somewhere during this process the font in memory is somehow corrupted and therefore FoontName is not returned accurately. I suspect now, that perhaps it may be something to do with the use of the same font handle across different buffers AND the TextAreaGadget? I understand normally that SetFont requires a valid graphics buffer, whilst SetTextAreaFont only requires the gadget despite them both referring to the same Loaded font handle... |
| ||
Floyd's gone rather quiet recently, and I'm no further to solving this issue - I only seem to find the problem becoming stranger. I made a few adjustments to prevent the TextArea gadget from being accessed when the GraphicsBuffer() is set to the ImageBuffer() and also added a few more debug checks on the actual result of FontName() at various places: Here's the Title-specific functions now, with the added debug checks [see especially "UpdateTitleParams()"] and the relevant debug output: Const DEF_TIT_TEXT$="Default" Const TIT_WYSIWYG_IMAGE_FLAG_DYNAMIC=2 Global TIT_WYSIWYG_IMAGE% Function InitialiseTitle() Debug("INIT: Initialise Title") InitialiseTitleTextArea InitialiseTitleEditButton InitialiseTitleTypeface InitialiseTitleText SetTitle CompleteTitleInitialisation End Function Function SetTitle() UpdateTitleParams UpdateTitleImage End Function Function InitialiseTitleTextArea() Debug("INIT (TITLE): Initialise textbox gadget dimensions") ; If (UI_TIT_GAD_TEXTBOX) ; Debug("TITLE: Release previous textbox gadget 0x"+Str(UI_TIT_GAD_TEXTBOX)) ; FreeGadget UI_TIT_GAD_TEXTBOX ; UI_TIT_GAD_TEXTBOX=0 ; End If Local W=(GUIDELINE_HEIGHT*CANVAS_Y_RATIO)-2 Local H=(((GUIDELINE_SPINE_WIDTH*CANVAS_X_RATIO)-2)*1.5) UI_TIT_GAD_TEXTBOX=CreateTextArea(0,0,W,H,UI_MAIN_WINDOW,UI_TIT_WORDWRAP) Debug("TITLE: Textbox gadget reference 0x"+Str(UI_TIT_GAD_TEXTBOX)+" created with dims: "+Str(W)+" X "+Str(H)) End Function Function InitialiseTitleEditButton() ; SetGenericFont UI_GAD_BUTTON_X=CANVAS_OFFSET_X UI_GAD_BUTTON_Y=CANVAS_OFFSET_Y + (GUIDELINE_SPINE_WIDTH*CANVAS_X_RATIO)*2 UI_GAD_BUTTON_W=StringWidth(UI_TIT_GAD_BUTTON_TEXT)*1.5 UI_GAD_BUTTON_H=StringHeight(UI_TIT_GAD_BUTTON_TEXT)*1.5 UI_TIT_GAD_BUTTON=CreateButton(UI_TIT_GAD_BUTTON_TEXT,UI_GAD_BUTTON_X,UI_GAD_BUTTON_Y,UI_GAD_BUTTON_W,UI_GAD_BUTTON_H,UI_MAIN_WINDOW) HideGadget UI_TIT_GAD_BUTTON ; UnSetGenericFont End Function Function InitialiseTitleText() SetTextAreaText UI_TIT_GAD_TEXTBOX,DEF_TIT_TEXT$ End Function Function InitialiseTitleTypeface() Debug("INIT (TITLE): Initialise Typeface") Local Size=(GUIDELINE_SPINE_WIDTH*CANVAS_X_RATIO) If (Not(GetTemplateSlimline())) Size=Size*0.5 End If UI_TIT_GAD_TYPEFACE=LoadFont(FONT_DEFAULT_TYPEFACE,Size);*FONT_DEF_LINE_SPACING#) UI_TIT_GAD_FONT_NAME=FontName(UI_TIT_GAD_TYPEFACE) UI_TIT_GAD_FONT_FLAGS=GetFontFlags(UI_TIT_GAD_TYPEFACE) Debug("INIT (TITLE): Loaded new Typeface "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" Size: "+Str(FontSize(UI_TIT_GAD_TYPEFACE))+" to reference: 0x"+Str(UI_TIT_GAD_TYPEFACE)+" with flags: 0x"+Str(UI_TIT_GAD_FONT_FLAGS)) End Function Function CompleteTitleInitialisation() HideGadget UI_TIT_GAD_TEXTBOX Debug("INIT (TITLE): Title Initialised") End Function Function UnInitialiseTitleTypeface() If (UI_TIT_GAD_TYPEFACE) Debug("INIT (TITLE): Release Typeface Data "+Chr(34)+UI_TIT_GAD_FONT_NAME$+Chr(34)+" 0x"+Str(UI_TIT_GAD_TYPEFACE)) UI_TIT_GAD_FONT_NAME$="" FreeFont UI_TIT_GAD_TYPEFACE UI_TIT_GAD_TYPEFACE=0 End If End Function Function SetTitleColours() Local TextR=Red(UI_TIT_GAD_COLOUR) Local TextG=Green(UI_TIT_GAD_COLOUR) Local TextB=Blue(UI_TIT_GAD_COLOUR) Local BackR=Red(TEMPLATE_SPINE_COLOUR) Local BackG=Green(TEMPLATE_SPINE_COLOUR) Local BackB=Blue(TEMPLATE_SPINE_COLOUR) SetTextAreaColor UI_TIT_GAD_TEXTBOX, TextR, TextG, TextB, FONT_FORE_FLAG SetTextAreaColor UI_TIT_GAD_TEXTBOX, BackR, BackG, BackB, FONT_BACK_FLAG Debug("TITLE (SET COLOUR): Colours set to FOREGROUND: "+Str(UI_TIT_GAD_COLOUR)+" BACKGROUND: "+Str(TEMPLATE_SPINE_COLOUR)) End Function Function ClearTitle() If (GetTitleClear()) Debug("TITLE (CLEAR): Title Text already null") Else SetTitleClear End If End Function Function PickTitleColour() Local Col=RequestColor(Red(UI_TIT_GAD_COLOUR),Green(UI_TIT_GAD_COLOUR),Blue(UI_TIT_GAD_COLOUR)) Local RGB=RGBa(RequestedRed(),RequestedGreen(),RequestedBlue()) If (Not(Col)) Debug("TITLE (PICK COLOUR): Pick cancelled") Else Debug("TITLE (PICK COLOUR): Picked "+Str(RGB)) End If If (RGB<>UI_TIT_GAD_COLOUR) UI_TIT_GAD_COLOUR=RGB SetTitle UpdateWYSIWYG Return End If Debug("TITLE (PICK COLOUR): No change in Colour") End Function Function PickTitleFont() Debug("TITLE (BEFORE PICK): Previous: "+FontName(UI_TIT_GAD_TYPEFACE)) Local NewFont=RequestFont() If (Not(NewFont)) Debug("TITLE (PICK CANCELLED): Previous "+FontName(UI_TIT_GAD_TYPEFACE)) Debug("TITLE (PICK TYPEFACE): Invalid / null selection or request cancelled. No Typeface change applied.") Return End If Debug("TITLE (PICK TYPEFACE): Picked 0x"+Str(NewFont)) Debug("TITLE (AFTER PICK): Previous: "+FontName(UI_TIT_GAD_TYPEFACE)) Local PickedName$=FontName(NewFont) If (UI_TIT_GAD_TYPEFACE) If (PickedName=UI_TIT_GAD_FONT_NAME) If (FontSize(NewFont)=FontSize(UI_TIT_GAD_TYPEFACE)) If (FontStyle(NewFont)=FontStyle(UI_TIT_GAD_TYPEFACE)) If (FontAscent(NewFont)=FontAscent(UI_TIT_GAD_TYPEFACE)) If (FontDescent(NewFont)=FontDescent(UI_TIT_GAD_TYPEFACE)) FreeFont NewFont Debug("TITLE (PICK TYPEFACE): Selection is identical to current Typeface. No change applied.") Return End If End If End If End If End If Debug("TITLE (PICK TYPEFACE): Plugging memory leaks for previous Typeface 0x"+Str(UI_TIT_GAD_TYPEFACE)) UnInitialiseTitleTypeface End If UI_TIT_GAD_TYPEFACE=NewFont UI_TIT_GAD_FONT_NAME=PickedName UI_TIT_GAD_FONT_FLAGS=GetFontFlags(NewFont) Debug("TITLE (PICK TYPEFACE): Loaded new Typeface "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" Size: "+Str(FontSize(UI_TIT_GAD_TYPEFACE))+" to reference: 0x"+Str(UI_TIT_GAD_TYPEFACE)+" with flags: 0x"+Str(UI_TIT_GAD_FONT_FLAGS)) SetTitle UpdateWYSIWYG End Function Function SetTitleFont() Debug("TITLE (SETFONT): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) SetTextAreaFont UI_TIT_GAD_TEXTBOX,UI_TIT_GAD_TYPEFACE UI_TIT_GAD_FONT_NAME$=FontName(UI_TIT_GAD_TYPEFACE) UI_TIT_GAD_FONT_FLAGS=GetFontFlags(UI_TIT_GAD_TYPEFACE) Debug("TITLE (SET TYPEFACE): Typeface Set to "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" Size: "+Str(FontSize(UI_TIT_GAD_TYPEFACE))+" to reference: 0x"+Str(UI_TIT_GAD_TYPEFACE)+" with flags: 0x"+Str(UI_TIT_GAD_FONT_FLAGS)) End Function Function GetTitleClear() Return (TextAreaText(UI_TIT_GAD_TEXTBOX)="") End Function Function SetTitleClear() Debug("TITLE (RELEASE): Content released from: 0x"+Str(UI_TIT_GAD_TEXTBOX)) SetTextAreaText UI_TIT_GAD_TEXTBOX,"" End Function Function UpdateTitleParams() Debug("TITLE (UPDATE): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) Debug("TITLE (UPDATE): Lock textbox gadget 0x"+Str(UI_TIT_GAD_TEXTBOX)) LockTextArea UI_TIT_GAD_TEXTBOX Debug("TITLE (UPDATE): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) SetTitleFont Debug("TITLE (UPDATE): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) SetTitleColours Debug("TITLE (UPDATE): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) UnlockTextArea UI_TIT_GAD_TEXTBOX Debug("TITLE (UPDATE): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) Debug("TITLE (UPDATE): UnLock textbox gadget 0x"+Str(UI_TIT_GAD_TEXTBOX)) End Function Function UpdateTitleImage() ClearTitleWYSIWYGImage Local TextString$=RemoveInvalidTitleCharacters(TextAreaText(UI_TIT_GAD_TEXTBOX)) If (Replace(TextString," ","")<>"") Local Buffer=GraphicsBuffer() Local Image=CreateImage(1,1,1,TIT_WYSIWYG_IMAGE_FLAG_DYNAMIC) Local IBuffer=ImageBuffer(Image) SetBuffer(IBuffer) SetFont UI_TIT_GAD_TYPEFACE Debug("FONT: Main Typeface Set to "+Chr(34)+FontName(UI_TIT_GAD_TYPEFACE)+Chr(34)+" reference 0x"+Str(UI_TIT_GAD_TYPEFACE)) Local W=StringWidth(TextString) Local H=StringHeight(TextString) If (W*H) If W>(GUIDELINE_HEIGHT*CANVAS_Y_RATIO) Then W=GUIDELINE_HEIGHT*CANVAS_Y_RATIO If H>(GUIDELINE_SPINE_WIDTH*CANVAS_X_RATIO)Then H=GUIDELINE_SPINE_WIDTH*CANVAS_X_RATIO SetBuffer(Buffer) ResizeImage Image,W,H TIT_WYSIWYG_IMAGE=Image SetBuffer(IBuffer) Local X=Floor(W Shr True) Local Y=Floor(H Shr True) LockBuffer IBuffer SetBufferColor(TEMPLATE_SPINE_COLOUR) If (UI_TIT_GAD_COLOUR=0) ;Fix for Masked 0,0,0 SetColour(1) Else SetColour(UI_TIT_GAD_COLOUR) End If Text X,Y,TextString,True,True UnlockBuffer IBuffer SetBuffer(Buffer) RotateImage TIT_WYSIWYG_IMAGE,90 MidHandle TIT_WYSIWYG_IMAGE Debug("WYSIWYG (TITLE): Image created 0x"+Str(TIT_WYSIWYG_IMAGE)+" With Dimensions: "+Str(W)+" x "+Str(H)) Return Else FreeImage Image SetBuffer(Buffer) End If End If TIT_WYSIWYG_IMAGE=0 Debug("WYSIWYG (TITLE): Image not created due to invalid dimensions: "+Str(W)+" x "+Str(H)) End Function Function ClearTitleWYSIWYGImage() If (TIT_WYSIWYG_IMAGE) Debug("WYSIWYG (TITLE): Release memory for 0x"+Str(TIT_WYSIWYG_IMAGE)) FreeImage TIT_WYSIWYG_IMAGE TIT_WYSIWYG_IMAGE=0 Else Debug("WYSIWYG (TITLE): No memory to release") End If End Function Function DrawTitleImage() If (TIT_WYSIWYG_IMAGE) Local OFFSET_X=(GUIDELINE_REAR_WIDTH+(GUIDELINE_SPINE_WIDTH*0.5)) Local OFFSET_Y=(GUIDELINE_HEIGHT*0.5) Local X#=GUIDELINE_X+OFFSET_X Local Y#=GUIDELINE_Y+OFFSET_Y X=X*CANVAS_X_RATIO Y=Y*CANVAS_Y_RATIO X=X-0.5 ; Fix for floating point calculations and 0.5mm ;FocusOnWYSIWYGBuffer() Debug("WYSIWYG (TITLE): Drawing Image at "+Str(X)+" , "+Str(Y)) DrawImage TIT_WYSIWYG_IMAGE,X,Y End If End Function Function RemoveInvalidTitleCharacters$(Title$) Title=Trim(Title) Local Iter Local Check Local Ascii For Check= 0 To 31 For Iter=Len(Title) To 1 Step -1 Ascii=Asc(Mid(Title,Iter,1)) If (Ascii=Check) Title=TrimStringMid(Title,Iter,1) End If Next Next Return Title End Function Function GetTitleFontFlags() Return (GetFontFlags(UI_TIT_GAD_TYPEFACE)) End Function 13:38:23 | INIT: Initialise Title 13:38:23 | INIT (TITLE): Initialise textbox gadget dimensions 13:38:23 | TITLE: Textbox gadget reference 0x52078448 created with dims: 646 X 37 13:38:23 | INIT (TITLE): Initialise Typeface 13:38:23 | INIT (TITLE): Loaded new Typeface "Blitz" Size: 27 to reference: 0x52078800 with flags: 0x1 13:38:23 | TITLE (UPDATE): Typeface is: Blitz 13:38:23 | TITLE (UPDATE): Lock textbox gadget 0x52078448 13:38:23 | TITLE (UPDATE): Typeface is: Blitz 13:38:23 | TITLE (SETFONT): Typeface is: TITLE |
| ||
I've gone quiet because I don't know what to say. trying to reproduce the error and narrow down That's the right attitude, but your posted code has grown to 324 lines and is still a fragment that nobody can actually run. |
| ||
I thought it best to post the full "Title" functionality which show all the relevant functions and any SetFont or SetTextAreaFont (includiing any FreeFont) commands I can try to produce a runnable snippet that contains the same features and hopefully reproduce the error, but as from my recent bug-forumm post - I think it is almost definitely related to changing buffers and fonts without a graphics window. |
| ||
Okay here's a straightforward, procedural copy of all the relevant funcitonality which I only changed to remove calls to functions that were unnnecessary (such as getting the RGB colour components or determining certain sizes - which I'm pretty sure have no bearing on the issue) This compiles as-is and will produce the error, but it is intermittent and inconsistent so you may need to compile a few times and check the last line of the ddebug output each time to see when it happens (should be within 20 times - at least, it was around 10 for me) There's no logical explanation I can find as to why FontName should be giving a different result between each call at the end. I really hope this highlights the issue I'm having and sorry it's not been easy to describe or narrow it down, but I do thank you for looking into it! Global UI_MAIN_WINDOW=CreateWindow("Window",0,0,800,600) Const UI_TIT_WORDWRAP=1 Const FONT_DEFAULT_TYPEFACE$="Blitz" Const DEF_TIT_TEXT$="Movie" Const TIT_WYSIWYG_IMAGE_FLAG_DYNAMIC=2 Global TIT_WYSIWYG_IMAGE% Global UI_TIT_GAD_TEXTBOX Global UI_TIT_GAD_BUTTON Global UI_TIT_GAD_TYPEFACE Global UI_TIT_GAD_FONT_NAME$ Global UI_TIT_GAD_FONT_FLAGS=1 Const FONT_FORE_FLAG=0 Const FONT_BACK_FLAG=1 DebugLog("INIT: Initialise Title") DebugLog("INIT (TITLE): Initialise textbox gadget dimensions") Local W=768 Local H=20 UI_TIT_GAD_TEXTBOX=CreateTextArea(0,0,W,H,UI_MAIN_WINDOW,UI_TIT_WORDWRAP) DebugLog("TITLE: Textbox gadget reference 0x"+Str(UI_TIT_GAD_TEXTBOX)+" created with dims: "+Str(W)+" X "+Str(H)) UI_GAD_BUTTON_X=20 UI_GAD_BUTTON_Y=50 UI_GAD_BUTTON_W=50 UI_GAD_BUTTON_H=30 UI_TIT_GAD_BUTTON=CreateButton("OK",UI_GAD_BUTTON_X,UI_GAD_BUTTON_Y,UI_GAD_BUTTON_W,UI_GAD_BUTTON_H,UI_MAIN_WINDOW) HideGadget UI_TIT_GAD_BUTTON If (UI_TIT_GAD_TYPEFACE) DebugLog("INIT (TITLE): Release Typeface Data "+Chr(34)+UI_TIT_GAD_FONT_NAME$+Chr(34)+" 0x"+Str(UI_TIT_GAD_TYPEFACE)) UI_TIT_GAD_FONT_NAME$="" FreeFont UI_TIT_GAD_TYPEFACE UI_TIT_GAD_TYPEFACE=0 End If DebugLog("INIT (TITLE): Initialise Typeface") Local Size=27 UI_TIT_GAD_TYPEFACE=LoadFont(FONT_DEFAULT_TYPEFACE,Size);*FONT_DEF_LINE_SPACING#) UI_TIT_GAD_FONT_NAME=FontName(UI_TIT_GAD_TYPEFACE) DebugLog("INIT (TITLE): Loaded new Typeface "+Chr(34)+UI_TIT_GAD_FONT_NAME+Chr(34)+" Size: "+Str(FontSize(UI_TIT_GAD_TYPEFACE))+" to reference: 0x"+Str(UI_TIT_GAD_TYPEFACE)+" with flags: 0x"+Str(UI_TIT_GAD_FONT_FLAGS)) SetTextAreaText UI_TIT_GAD_TEXTBOX,DEF_TIT_TEXT$ DebugLog("TITLE (UPDATE): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) DebugLog("TITLE (UPDATE): Lock textbox gadget 0x"+Str(UI_TIT_GAD_TEXTBOX)) LockTextArea UI_TIT_GAD_TEXTBOX DebugLog("TITLE (UPDATE): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) ; SOMEHOW THE FONTNAME IS CORRUPTED BETWEEN THE LINE ABOVE AND THE LINE BELOW INTERMITTENTLY DebugLog("TITLE (SETFONT): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE)) ; YOU MAY NEED TO RUN MULTIPLE TIMES FOR THE EFFECT TO BE APPARENT |
| ||
No idea what's happening, but this is amusing. The first thing that happens is I get *****INTERNAL ERROR***** Attempt to release <unknown> object. The error is apparently at the last line of code: DebugLog("TITLE (SETFONT): Typeface is: "+FontName(UI_TIT_GAD_TYPEFACE))If I delete that the INTERNAL ERROR goes away. Now the good part, I replace the deleted line with fname$ = FontName(UI_TIT_GAD_TYPEFACE) and the error is back, except it is Attempt to retain <unknown> object. I also thought LockTextArea UI_TIT_GAD_TEXTBOX might be to blame, since there is no matching UnLockTextArea. That must be mistake, but it doesn't seem to affect the release/retain error, whatever that is. |
| ||
The Lock/UnLock doesn't actually seem to affect anything at all - there was initially an UnLock line (Can be put in again, even right after the Lock line), but since the "<unknown> object" error halts execution right there and then at the last line, I just removed everything afterwards. Whilst also something intriguing and problematic, the <unknown object> errors aren't the reason for this thread, though it may be they are connected in some way - Did you at all repeat running the test a few times until you saw the FontName() returned (in the DebugLog) actually change and become corrupted? At least, I am beginnning to feel slightly more reassured it's not just my code! Any and all suggestions for alternative methods gladly appreciated!!! |
| ||
I think I saw "Blitz" change to "TITLE", but not sure since I got distracted by the internal error, which I still don't understand. As for the Lock/Unlock I think the general advice is to lock, do whatever it was you wanted to the buffer and then immediately unlock. This is to avoid possible interactions with other commands. They may seem unrelated but who knows. My only other vague advice is that you are not using the normal form of a BlitzPlus program with GUI elements. Maybe that's causing trouble. What I mean by normal form is this general structure: Set things up Repeat Wait for event Deal with event ForeverIf you haven't done it already take a look at the BlitzPlus User Guide. To find it click the Home icon in the IDE, just below the menu bar. You may want to start with Appendix A1 which summarizes some differences from previous Blitzes. Disclaimer: Despite the fact that I'm here handing out advice I really don't know a lot about the features of BlitzPlus which were not already in Blitz3D. |
| ||
"I think I saw "Blitz" change to "TITLE", but not sure" Yes, that would be it. Incidentally, it seems to sometimes actually take on the value of something like "TITLE (SETFONT): Typeface is:" - which is interestingly the string passed to the debuglog. There may be a connection, since (part of my initial suspicion) if you remove references to FontName within the DebugLines, the "<unknown object>" error disappears: Global UI_MAIN_WINDOW=CreateWindow("Window",0,0,800,600) Const UI_TIT_WORDWRAP=1 Const FONT_DEFAULT_TYPEFACE$="Blitz" Const DEF_TIT_TEXT$="Movie" Const TIT_WYSIWYG_IMAGE_FLAG_DYNAMIC=2 Global TIT_WYSIWYG_IMAGE% Global UI_TIT_GAD_TEXTBOX Global UI_TIT_GAD_BUTTON Global UI_TIT_GAD_TYPEFACE Global UI_TIT_GAD_FONT_NAME$ Global UI_TIT_GAD_FONT_FLAGS=1 Const FONT_FORE_FLAG=0 Const FONT_BACK_FLAG=1 Local W=768 Local H=20 UI_TIT_GAD_TEXTBOX=CreateTextArea(0,0,W,H,UI_MAIN_WINDOW,UI_TIT_WORDWRAP) UI_GAD_BUTTON_X=20 UI_GAD_BUTTON_Y=50 UI_GAD_BUTTON_W=50 UI_GAD_BUTTON_H=30 UI_TIT_GAD_BUTTON=CreateButton("OK",UI_GAD_BUTTON_X,UI_GAD_BUTTON_Y,UI_GAD_BUTTON_W,UI_GAD_BUTTON_H,UI_MAIN_WINDOW) HideGadget UI_TIT_GAD_BUTTON Local Size=10;27 UI_TIT_GAD_TYPEFACE=LoadFont(FONT_DEFAULT_TYPEFACE,Size);*FONT_DEF_LINE_SPACING#) UI_TIT_GAD_FONT_NAME=FontName(UI_TIT_GAD_TYPEFACE) SetTextAreaText UI_TIT_GAD_TEXTBOX,DEF_TIT_TEXT$ x$=FontName(UI_TIT_GAD_TYPEFACE) DebugLog(x) stop "As for the Lock/Unlock I think the general advice is to lock, do whatever it was you wanted to the buffer and then immediately unlock. This is to avoid possible interactions with other commands. They may seem unrelated but who knows." Yes, I pretty much tried this, but didn't seem to affect anything at all. "My only other vague advice is that you are not using the normal form of a BlitzPlus program with GUI elements. Maybe that's causing trouble." In my actual program, this is how the program flow operates, only prior to the loop, the initial defaults and gadgets need to be set up and the functions here represent a small part of that. The main window and menu system initialisation are elsewhere in my program code and function correctly, but do not seem to be a factor in this issue. |
| ||
I think there might be some workaround for this issue if QueryObject(hn,3) is used for the font. I'm working on it and will update as I have more info... |