GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 30, 2014 12:16 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: draw event stops responding - GUI stops rendering
PostPosted: Tue Apr 29, 2014 9:50 pm 
Offline

Joined: Mon Apr 28, 2014 12:51 pm
Posts: 4
Location: Canada
I'm writing a CNC controller / gcode interpreter for a CNC router/mill that I'm building, using phidget controllers connected through USB.
The application works fine for a while then for no reason the entire GUI stops rendering. All the functions and buttons still work, the UI just doesn't redraw.
I've narrowed it down to the draw event, which stops being triggered.
I get no errors, no warnings of any kind.
I think it has something to do with updating the text in the x,y,z position displays.
I'm using 3 gtk_label widgets to display the x,y and z position of the cutter head.
I have a handler that updates the text in the labels with gtk_label_set_text() when the phidget unipolar motor controller detects a position change.
Is it possible that the text is being updated too quickly ? The maximum rate is 383 updates per second.
As a side note I swapped the labels with entry widgets and it does the same thing.
I'm using GTK-3.4.2, pango 1.30.0, pixman 0.32.2, cairo 1.10.2
Eclipse IDE
I'm running Ubuntu 12.04 LTS 32bit as a virtualbox 4.3.10 guest on a windows 7 host.
I've written a number of other GTK applications which all work perfectly. None of them however have any text changing at such a rapid rate.

I'm wondering if anyone has had a similar experience ?
Anyone have any suggestions on how to proceed to determine the cause?

I can't seem to debug into the inner workings of gtk. There's no where that I can put a breakpoint that will stop execution when the problem occurs.
Everything still works. The only function that I've written that stops responding is the function I've connected to run after the default draw event handler. This is understandable if the draw event for all widgets has stopped responding or being triggered.
Is there a way to print the events/signals that are triggered to a console as the program runs ?

Any help is greatly appreciated as the position display is a key part of the application.


Top
 Profile  
 
 Post subject: Re: draw event stops responding - GUI stops rendering
PostPosted: Thu May 01, 2014 6:33 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 766
Location: UK
Hi,

The 383 updates per second is very high as most monitors only refresh between 60 to 120 times per second. It should not be a problem for GTK+ to redraw at that speed as any redraw requests that would be over drawn by a new request will be discarded.

Are you using threads to read from the USB device and call GTK+ to do the displaying of information. If so then this could be the cause of your problem. GTK+ is thread aware but not thread safe and calling GTK+ from multiple threads can cause it to lock up internally.

The best solution in this case would be to move all GTK+ calls to the main thread and have some form of message passing system from the worker thread to the main thread to allow the display to update.

_________________
E.


Top
 Profile  
 
 Post subject: Re: draw event stops responding - GUI stops rendering
PostPosted: Thu May 01, 2014 3:43 pm 
Offline

Joined: Mon Apr 28, 2014 12:51 pm
Posts: 4
Location: Canada
I've used phidgets a lot without using gdk_threads_init, enter and leave. I've never explicitly created any separate threads in my applications.
I suppose I really should use them since initializing the phidgets creates multiple threads for each device. The process is just hidden in the phidget api libraries so it's easy to overlook.

The "position_changed_handler" is in the main thread but it is called by the phidget thread which passes all the pertinent information to the main thread so all my gtk calls are in the main thread.

So if I add gdk_threads_init at the start of my app, do I put the gdk_threads_enter and leave around my code in the position_changed_handler or in my main function to cover the whole app ?

I guess if that doesn't work I can have the "position_changed_handler" change the values in memory, then add a time out function to do the label text updating when the values in memory change.

I think you've pointed me in the right direction.
I'll let you know what happens.
Thanks very much.


Top
 Profile  
 
 Post subject: Re: draw event stops responding - GUI stops rendering
PostPosted: Thu May 01, 2014 6:54 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 766
Location: UK
By the sounds of it I may have been right that it was a threading issue.

It would be best not to use gdk_threads_init(), gdk_threads_enter () and gdk_threads_leave () as these are deprecated from GTK+ v3.6 and with Glib v2.32 threads are already initialised.
Quote:
I guess if that doesn't work I can have the "position_changed_handler" change the values in memory, then add a time out function to do the label text updating when the values in memory change.

I think that would be the best solution as that keeps the GUI and worker threads separated with a well defined interface.

_________________
E.


Top
 Profile  
 
 Post subject: Re: draw event stops responding - GUI stops rendering - SOLV
PostPosted: Fri May 02, 2014 1:05 am 
Offline

Joined: Mon Apr 28, 2014 12:51 pm
Posts: 4
Location: Canada
Well thank you my friend for pointing me in the right direction.
I was definitly a threading issue.
Both solutions work equally well but since the thread functions are deprecated in the newer version of GTK+ I will stick with keeping thing separated and add the timeout routine.

The obvious things are often the hardest to see when your right in the middle of it.

Thanks very much this issue is SOLVED!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group