OS: Ubuntu 11.10, 32-bit, all patches applied till 9th february 2012 - executed in VirtualBox.
During my attempts to produce a working sample to document an error with DrawText() used in threads, i ran into several problems which seem to point at fundamental problems of using 2dDrawing in threads on linux with PureBasic.
The following examples are compiled with "threadsafe" enabled and executable format "Linux".
ImgID.i = CreateImage(#PB_Any, 200, 200, #PB_Image_DisplayFormat)
If (ImgID = 0)
If (StartDrawing(ImageOutput(ImgID)) = 0)
DNum.i = Random(20)
If (DNum > 0)
NewImageID.i = CImage()
If (NewImageID <> 0)
TestWindowID.i = OpenWindow(#PB_Any, 0, 0, 400, 400, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If (TestWindowID = 0)
ThreadID.i = CreateThread(@CImageThread(), 0)
If (ThreadID = 0)
Event = WindowEvent()
; NewImageID.i = CImage()
; If (NewImageID <> 0)
Until Event = #PB_Event_CloseWindow
This results in the program being quickly aborted with the following error message:
The program 'Test1' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadLength (poly request too large or internal Xlib length erro'.
(Details: serial 33020 error_code 16 request_code 55 minor_code 0)
(Note to programmers: normally, X errors are reported asynchronously;
that is, you will receive the error a while after causing it.
To debug your program, run it with the --sync command line
option to change this behavior. You can then get a meaningful
backtrace from your debugger if you break on the gdk_x_error() function.)
If you don't spawn the thread or use a thread which doesnt use 2D-Drawing commands and do the same 2DDrawing in the main thread, everything works as expected.