[5.20 LTS] SetGadgetFont causes WindowedScreen crash on exit

Post bugreports for the Windows version here
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

[5.20 LTS] SetGadgetFont causes WindowedScreen crash on exit

Post by Rescator »

This is a really weird one.

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
Then test this code

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)
And then close the test window. Here it crashes when closing.


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?
SilentCatcher
New User
New User
Posts: 2
Joined: Sat Sep 28, 2013 9:49 am
Location: Eberbach (Germany)

Re: [5.20 LTS] SetGadgetFont causes WindowedScreen crash on

Post by SilentCatcher »

Confirmed, crashes with and without debugger
Windows 8 (64bit) / Ubuntu 13.04 (64bit) / Purebasic 5.20 LTS (32 + 64bit)
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: [5.20 LTS] SetGadgetFont causes WindowedScreen crash on

Post by Rescator »

Some more info related to the above, A larger program of mine (which does not use SetGadgetFont) also crashes on exit.
3 DLLs exist each compiled with the subsystem DirectX11 and OpenGL and no subsystem (DirectX9), otherwise the DLLs are identical.
The DLL is loaded by and the functions used by the same thread (main process thread) as the program GUI and main window.

The odd thing is that when loading and using the DirectX9 dll and the OpenGL dll the program crashes on exit.
But it does not crash if the DirectX11 dll is used.

The issue is at the exit of PureBasic program itself as it also crashes if End is used and anything beyond that point is obviously not something I can fix.

Not sure if this helps any (Fred/Freak), I'll try and create some example code that replicate this, but it's a large code and may take some while to narrow down what other code triggers this issue.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: [5.20 LTS] SetGadgetFont causes WindowedScreen crash on

Post by Rescator »

I have also noticed something else that is odd.
If a UAC/elevation occurs (darkened screen with password box etc) then DirectX9 and DirectX11 rendering stops. But OpenGL however will continue rendering.
Again the only thing different is the subsystem the code is otherwise identical, this combined with the behavior here http://www.purebasic.fr/english/viewtop ... =4&t=56728
Again note that this is in a larger program and I do not have any isolated code to replicate this UAC annoyance. Also note that this is with all the code in the main executable (and not in a dll).

Does anybody else have any clue as to what is going on or able to provide a short example?

So far I've stumbled across these issues:
  • WindowedScreen causes crash on exit if SetGadgetFont is used in exe and the rendering stuff is in a dll (Example in first post)
  • DirectX9 WindowedScreen dies if a fullscreen app is started, DirectX11 and OpenGL subsystems not affected http://www.purebasic.fr/english/viewtop ... =4&t=56728
  • WindowedScreen causes crash on exit even if SetGadgetFont is not used in exe and the rendering stuff is in a dll (not narrowed down yet) for DirectX9 and OpenGL subsystems, DirectX11 subsystem not affected.
  • WindowedScreen rendering "dies" if a UAC elevation prompt is triggered and DirectX9 or DirectX11 subsystem is used, OpenGL subsystem not affected.
*scratches head* very frustrating indeed.
My current workaround is to use only the OpenGL subsystem (up until now the end users where able to choose if OpenGL/DirectX9/DirectX11 was to be used for the rendering), and not put the rendering code in a DLL.
Post Reply