If a WindowedScreen is created in a DLL, and SetGadgetFont is just referenced (not even used) in the program then the program crashes on exit.
Compile this source to a DLL
Code: Select all
ProcedureDLL.i TestRenderer_Init(windowid,width,height,framerate)
Protected result.i=#False
If InitSprite()
If OpenWindowedScreen(windowid,0,0,width,height)
SetFrameRate(framerate)
result=#True
EndIf
EndIf
ProcedureReturn result
EndProcedure
ProcedureDLL.i TestRenderer_DeInit()
CloseScreen()
ProcedureReturn #Null
EndProcedure
ProcedureDLL.i TestRenderer_Flip()
FlipBuffers()
ProcedureReturn #Null
EndProcedure
Code: Select all
EnableExplicit
Prototype.i TestRenderer_DeInit()
Global TestRenderer_DeInit.TestRenderer_DeInit
Prototype.i TestRenderer_Init(windowid,width,height,framerate)
Global TestRenderer_Init.TestRenderer_Init
Prototype.i TestRenderer_Flip()
Global TestRenderer_Flip.TestRenderer_Flip
If OpenLibrary(0,"test.dll")=#False
End
EndIf
TestRenderer_DeInit=GetFunction(0,"TestRenderer_DeInit")
If TestRenderer_DeInit=#False
End
EndIf
TestRenderer_Init=GetFunction(0,"TestRenderer_Init")
If TestRenderer_Init=#False
End
EndIf
TestRenderer_Flip=GetFunction(0,"TestRenderer_Flip")
If TestRenderer_Flip=#False
End
EndIf
define width.l,height.l,event.i
width=400
height=200
If OpenWindow(0,0,0,width,height,"test")
TestRenderer_Init(WindowID(0),width,height,25)
Repeat
event=WaitWindowEvent(2)
TestRenderer_Flip()
Until event=#PB_Event_CloseWindow
TestRenderer_DeInit()
EndIf
End
SetGadgetFont(#PB_Default,#PB_Default)
I'm not sure what is going on here. It's just really weird.
I spent ages hunting this one down in a large program.
Even weirder is that it causes a crash on exit regardless if the subsystem is DirectX9 or DirectX11 or OpenGL.
I can only speculate in that PureBasic cleanup is referencing the wrong pointer somewhere when cleaning up after either SetGadgetFont or OpenWidowedScreen, but why this only happens if OpenWidowedScreen is used fro a DLL I have no idea. Is SetGadgetFont tied to InitSprite somehow?