On Mar 20, 2007, at 3:53 PM, Martin Henne wrote:

> Unfortunately, my applicaton crashes and I dont know what I am
> doing wrong here :-( It works when I dont call 'drawAnimated()' in
> the thread, but then it becomes useless :-(
>
> Can someone help me here?

Yes, it crashes because you are calling drawing commands when it is  
not your turn to draw anything. If you application was single- 
threaded, you could use "myWidget->make_current()" and then start  
drawing, however, in a multithreaded application, only the main  
thread is allowed to draw. This is a restriction by some of the  
underlaying operating systems, nothing we can do about in FLTK.

But no worries, the solution is very simple. Let the thread do all  
the calculations, and as soon as it is done, call:

Fl::lock();
myWidget->redraw();
Fl::unlock();
Fl::awake();

Now as soon as the main thread can spare some time, it will call the  
"draw()" function of your widget. If you need to pass a value to the  
draw function, it is probably easiest to simply make that a member of  
your widget, so you'd get:

Fl::lock();
myWidget->draw_at(time);
myWidget->redraw();
Fl::unlock();
Fl::awake();

class MyWidget : public ...
{
   ...
   int draw_at_member;
   int draw_at() { return draw_at_member; }
   void draw_at(int da) { draw_at_memeber = da; }
}

void MyWidget::draw() {
   if (draw_at())
     drawAnimated(draw_at());
   else
     // draw whatever else
}

----
http://robowerk.com/


_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to