Can't reuse Canvas after FreeGadget

BlitzMax Forums/BlitzMax Programming/Can't reuse Canvas after FreeGadget

Chapman7(Posted 2015) [#1]
Import MaxGUI.Drivers

Local Window:TGadget = CreateWindow("test",0,0,1920,1080,Null,0)
Local Canvas:TGadget = CreateCanvas(0,0,Window.ClientWidth(), Window.ClientHeight(),Window,0)
SetGadgetLayout(Canvas,1,1,1,1)
CreateTimer(60)

Local FPS:Short
Local FPSFrames:Short
Local FPSTime:Int

EnablePolledInput()

While Not (AppTerminate() Or KeyHit(KEY_ESCAPE))
	SetGraphics CanvasGraphics(Canvas)
	Cls
	
	If MilliSecs() - FPSTime > 1000 Then
		FPS = FPSFrames
		FPSFrames = 0
		FPSTime = MilliSecs()
	Else
		FPSFrames = FPSFrames + 1
	EndIf
	
	DrawText(FPS, 0, 0)
	
	If KeyHit(KEY_F1) Then
		EndGraphics()
		FreeGadget(Canvas)
		FreeGadget(Window)
		Window = CreateWindow("test",0,0,800,600,Null,WINDOW_CENTER)
		Canvas = CreateCanvas(0,0,Window.ClientWidth(), Window.ClientHeight(),Window,0)
		SetGadgetLayout(Canvas,1,1,1,1)
		SetGraphics CanvasGraphics(Canvas)
	EndIf
	
	Flip 0
Wend


Can someone help me out here?

After I free the Canvas and Window and remake them, everything goes smooth until it's time to draw anything (DrawText)


skidracer(Posted 2015) [#2]
On Mac a GLShareContexts at top stopped font graphics becoming corrupt in new window.


AdamStrange(Posted 2015) [#3]
skidracer - thats a great tip about glsharecontexts. I've had weird errors like this :)


col(Posted 2015) [#4]
Hiya,

This post explains how to fix it


Chapman7(Posted 2015) [#5]
Thanks guys! I didn't have to rebuild modules, I was able to throw BumpGraphicsSeq() before EndGraphics() and it works like a charm! SkidRacer does that get it working on Mac as well?