[gtkmm] Problem with refreshing a DrawingArea in a multi-threaded program



 Hi, 
 
I'm having a problem realising some program with Gtkmm, and I don't manage
to  
solve it! (don't have all too much programming experience, actually, and
never  
mind Gtkmm experience). Maybe one of you can help me... 
 
I'm writing a program to visualize data from a laserscanner. I'm using a  
Gtkmm::DrawingArea to draw points at coordinates that I get from the  
laserscanner. 
 
The laserscanner is implemented as an active object. It inherits from some  
class "EventSource". 
 
For the DrawingArea, I wrote a derived class "LaserArea", which inherits
from  
"DrawingArea" and "EventListener". Being an EventListener, the laserarea has
a  
member function "onEvent(Event& e)", and can be attached to an EventSource
(in  
this case the laserscanner). 
 
Whenever the laserscanner has new data, it calls the "onEvent" of the  
laserarea. This causes the new data to be copied to the laserarea, and then
it  
calls draw_laserview(), which does the actual drawing of the points: 
 
 
void LaserArea::onEvent(MoRE_utilities::Event& event) 
{ 
  _mutex.acquire(); 
    for(unsigned int i = 0; i < _nrOfRanges; i++ ) 
    { 
      _range[i] =  
_laserscanner->rangeDouble(i);                                         
//_range, _cartx and _carty are arrays of doubles 
      _cartx[i] = _range[i] * sin(PI/180 * double(i)/2 - _angle); 
      _carty[i] = _range[i] * cos(PI/180 * double(i)/2 - _angle); 
    } 
  _mutex.release(); 
 
  draw_laserview(); 
} 
 
void LaserArea::draw_laserview() 
{ 
   pfclog << log << "draw_laserview()" << endm;             //Do some
logging 
     _mutex.acquire(); 
    _window->clear(); 
    _gc->set_foreground(_blue); 
    unsigned int i = 0; 
    for(unsigned int i = 0; i < _nrOfRanges; i++ ) 
    { 
      _window->draw_arc(_gc, true, get_width()/2 - _carty[i] * _zoom_scale -
 
3, get_height()/2 - _cartx[i] * _zoom_scale - 3 , 6, 6, 0, 23040); 
    } 
  _mutex.release(); 
} 
 
 
I also have a button "redraw", that calls "draw_laserview()" when pressed. 
draw_laserview() also gets called by on_expose_event(GdkEventExpose* e). 
 
 
When I press the button, everything get's drawn perfectly, als also when I  
resize the window the DrawingArea is in or do whatever makes
on_expose_event()  
get called. 
 
When onEvent is called however, only the first so many dots get drawn.  
Sometimes more, sometimes less, but for some reason not all of them. If I
then  
for instance move my mouse over the window, the drawingarea gets refreshed
and  
all the points are drawn. During this refresh, draw_laserview() is not
called,  
since it does not do the logging. Apparently it's not the
_window->draw_arc()  
that does the actual drawing, but some thread (?) that dies before finishing
 
its job, whenever it is started from onEvent... Or so?!? 
 
I tried to call a function do_actual_drawing() in onEvent (after calling  
draw_laserview()), which does this: 
 
void LaserArea::do_actual_drawing() 
{ 
  _window->get_geometry(_window_x, _window_y, _window_width, _window_height,
 
_window_depth); 
  _window->invalidate_rect(Gdk::Rectangle(_window_x, _window_y,
_window_width,  
_window_height), true); 
  _window->process_all_updates(); 
} 
 
But if I do that, I get an "Xlib: unexpected async reply" error (see  
http://www.faqs.org/faqs/x-faq/part7/section-15.html ). 
So that's apparently not a sollution. 
 
 
Anyone an idea? Maybe i should make onEvent send out an expose_event?  But
how  
do I do that? 
 
 
 
 
Then I also have some smaller questions: 
 
- How do I make a window focused when shown? 
- Are windows in windows possible (like e.g. having multiple documents open
in  
Word (yuk!))? 
- Is it possible to make a window appear at a certain position on the
screen?  
Well, preferrably not at hard-coded coordinates, but e.g. "if possible, next
 
to (thus not covering) another window". 
 
 
Thanks, and many greetings, 
 
 Johan Rutgeerts 
 
 
 

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]