CreateThread(CRASH AND BURN)
Posted: Sun Dec 09, 2012 4:34 am
I'm trying to get a small client/server running on Linux x64, unicode, though the OS shouldn't matter as this is stock, out of the box PB code. The code runs fine and does exactly what it should as it's written below (client connects, server says '200 Hello' and client responds with 'EXEC SOME CMD'), except that the UI is locked, which is why I need this running on a thread. However if I uncomment marked line 1 and comment marked line 2 out, everything crashes and burns. Can anyone advise on what I'm doing wrong?
[WARNING] test.pb (Line: 57)
[WARNING] GdK (CRITICAL): IA__gdk_window_get_events: assertion 'GDK_IS_WINDOW (window)' failed
[WARNING] test.pb (Line: 57)
[WARNING] GLib-GObject (CRITICAL): g_object_unref: assertion 'G_IS_OBJECT (object)' failed
Code: Select all
EnableExplicit
Procedure BlockingProxy(*Port.i)
InitNetwork()
#BufferLen = 65535
Define *Buffer = AllocateMemory(#BufferLen)
Define thisEvent.i
Define ClientID.i
Define Quit.i
If CreateNetworkServer(0, *Port)
Repeat
thisEvent = NetworkServerEvent()
If thisEvent
ClientID = EventClient()
Select thisEvent
Case #PB_NetworkEvent_Connect
SendNetworkString(ClientID, "200 Ready" + Chr(13) + Chr(10))
Case #PB_NetworkEvent_Data
ReceiveNetworkData(ClientID, *Buffer, #BufferLen)
MessageRequester("", "Client sent: " + PeekS(*Buffer, -1, #PB_Ascii), 0)
Case #PB_NetworkEvent_Disconnect
Quit = #True
EndSelect
EndIf
Until Quit = #True
CloseNetworkServer(0)
Else
MessageRequester("Error", "Can't create server.", 0)
EndIf
EndProcedure
Define MainQuit.i
Define MainEvent.i
OpenWindow(0, 250, 68, 504, 477, "Proxy Test", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
; CreateThread(@BlockingProxy(), 1119) ; <----- crash & burn ****** MARK 1
BlockingProxy(1119) ; <----- works as designed ****** MARK 2;
Repeat
MainEvent = WaitWindowEvent()
Select MainEvent
Case #PB_Event_CloseWindow
MainQuit = 1
EndSelect
Until MainQuit = 1