Page 1 of 1

library stalls, when OpenWindow somewhere

Posted: Wed May 31, 2023 9:36 pm
by HeX0R
As you can see OpenWindow() below in the library procedure OpenMyWindow() will never be called, but it stalls when trying to close the library.
I can either remove the OpenWindow() command or use a previous compiler (tested 5.73LTS) to make it end properly.

only tested with x64 compilers

Code: Select all

CompilerIf #PB_Compiler_ExecutableFormat = #PB_Compiler_DLL
	;create a test.so
	ProcedureDLL AttachProcess(Instance)
		Global WinID, ButtonID
	EndProcedure

	ProcedureDLL OpenMyWindow()
 		WinID    = OpenWindow(#PB_Any, 0, 0, 300, 200, "My Window", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
 		ButtonID = ButtonGadget(#PB_Any, 5, 5, 200, 24, "click me")
 		;BindEvent(#PB_Event_CloseWindow, @MyCloseWindow(), WinID)
		;BindGadgetEvent(ButtonID, @MyButtonClick())
	EndProcedure
	
	ProcedureDLL DetachProcess(Instance)

	EndProcedure
	
CompilerElse
	;test the test.so
	
	If OpenLibrary(0, "test.so") = 0
		End
	EndIf
	
	Procedure main()
		If OpenWindow(0, 0, 0, 400, 400, "Application", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
		
			Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
			CloseWindow(0)
			CloseLibrary(0)
			Debug "WTF?"
		EndIf
	EndProcedure
	
	main()
CompilerEndIf

Re: PB6.xx library stalls, when OpenWindow somewhere

Posted: Sat Jun 03, 2023 12:37 pm
by mk-soft
GTK is not thread-safe and therefore not easy to use in libraries.
Special processing is required for this.
/* get GTK thread lock */
gdk_threads_enter();

/* do any gtk */

/* Make sure all X commands are sent to the X server; not strictly
* necessary here, but always a good idea when you do anything
* from a thread other than the one where the main loop is running.
*/
gdk_flush ();

/* release GTK thread lock */
gdk_threads_leave();
Found here: https://www.geany.org/manual/gtk/gtk-faq/x482.html

Re: PB6.xx library stalls, when OpenWindow somewhere

Posted: Sat Jun 03, 2023 1:44 pm
by HeX0R
there are no threads in my example!

Re: PB6.xx library stalls, when OpenWindow somewhere

Posted: Sat Jun 03, 2023 1:52 pm
by mk-soft
The X-server (gdk) is used twice within the programme. Once in the MainScope and once in the Library.
This is probably not permissible. :cry:

Re: PB6.xx library stalls, when OpenWindow somewhere

Posted: Sun Feb 25, 2024 6:27 pm
by Fred
Using GUI in DLL isn't allowed

Re: library stalls, when OpenWindow somewhere

Posted: Sun Feb 25, 2024 9:31 pm
by HeX0R
Hmm...
o.k., that worked just fine in the past, creating GUI in a DLL (with bind events) and keep the WaitWindowEvent() in the main scope.

I have an application with DLL plugins, which need their own GUI, so how should I do this in future?

Re: library stalls, when OpenWindow somewhere

Posted: Mon Feb 26, 2024 11:25 am
by Fred
I wonder how it even worked before because all the internal structures to handle window/gadget ids are duplicated and not linked (you got one in you program and one in your dll). So rthe event system can't work as you need a single event loop per program. The safer way to do this if you want to enable a plugin system using UI in PB is to actually expose the OpenWindow() and gadget functions from your pogram in your DLL.