library stalls, when OpenWindow somewhere

Linux specific forum
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

library stalls, when OpenWindow somewhere

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB6.xx library stalls, when OpenWindow somewhere

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: PB6.xx library stalls, when OpenWindow somewhere

Post by HeX0R »

there are no threads in my example!
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB6.xx library stalls, when OpenWindow somewhere

Post 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:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB6.xx library stalls, when OpenWindow somewhere

Post by Fred »

Using GUI in DLL isn't allowed
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: library stalls, when OpenWindow somewhere

Post 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?
Fred
Administrator
Administrator
Posts: 16618
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: library stalls, when OpenWindow somewhere

Post 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.
Post Reply