I have a problem in my current project.
The task is to collect and display data in realtime. The collection and display of the data must be not interruptable when the user interacts with the program. So I can not do this in the main loop but in a separate thread.
To display the data I must use a very big image (and an ImageGadget in a ScrollAreaGadget).
So far so good. The strange behaviour occurs when I move one of the sliders rapidly to simulate the user interaction. In some cases (sometimes after 5 sec., sometimes after 50 sec.) it crashes and the debugger identifies the StartDrawing and shows the error message: The specified output in NULL (0 value).
Here is the code to reproduce it:
Code: Select all
EnableExplicit
#WindowMain = 0
#StatusBar = 0
#Image1 = 3
#ScrollGadget = 1
#ImageGadget = 2
#ImgXSize = 5000
#ImgYSize = 5000
Procedure MainThreadPr( dummy.l )
Repeat
If IsImage( #Image1 )
If StartDrawing( ImageOutput( #Image1 ) )
LineXY( 100, 100, 800, 100, Random( $FFFFFF ) )
StopDrawing()
SetGadgetState( #ImageGadget, ImageID( #Image1 ) )
EndIf
EndIf
Delay( 20 )
ForEver
EndProcedure
Procedure MainPR()
If OpenWindow( #WindowMain, 50, 50, 1000, 700, "Test" )
If CreateStatusBar( #StatusBar, WindowID( #WindowMain ) )
If CreateImage( #Image1, #ImgXSize, #ImgYSize, 16 )
If StartDrawing( ImageOutput( #Image1 ) )
Box( 0, 0, #ImgXSize, #ImgYSize, $C0C0C0 )
StopDrawing()
If CreateGadgetList( WindowID( #WindowMain ) )
ScrollAreaGadget( #ScrollGadget, 0, 27, WindowWidth( #WindowMain ), WindowHeight( #WindowMain )-50 , #ImgXSize, #ImgYSize, 10, #PB_ScrollArea_Single )
ImageGadget( #ImageGadget, 0, 0, #ImgXSize, #ImgYSize, ImageID( #Image1 ) )
CreateThread( @MainThreadPr(), 0 )
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
EndIf
EndIf
EndIf
EndIf
EndProcedure
MainPR()
The question for me now is:
Is the 2D drawing library really threadsave and if not, what can I do to perform this task?
Thanks


