Real-time Graphical Output on a wxPanel from within a wxThread

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
In need of some credit
In need of some credit
Posts: 1
Joined: Tue May 19, 2020 4:10 pm

Real-time Graphical Output on a wxPanel from within a wxThread

Post by philju » Tue May 19, 2020 4:48 pm

Hi there,

I'd like to produce real-time graphical output from a piece of code using a class derived from wxPanel, with drawing using wxBufferedPaintDC from within the wxPanel::OnPaint. I got this working very well with calls to:

Code: Select all

From within a Redraw method. However, this version of the code locked the interface and the process continued even after the window had been closed.

My current solution to this was to run the state update from within a wxThread, and to call my Redraw method to update the view from within the thread. For reasons that are currently unclear to me, the call to wxWindow::Update() produces a run-time error:
** (wxgraphicaloutput:11015): WARNING **: 17:26:57.095: (../atk-adaptor/bridge.c:993):atk_bridge_adaptor_init: runtime check failed: (root)
wxgraphicaloutput: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
The best current workaround I have is to comment out the call to wxWindow::Update(). This works to a point. I am finding that sometimes the graphics fail to update, but the code runs in the background.

I've included a simple bool flag to the creation of the wxThread to prevent more than one running at a time, but this doesn't fix the situation. I am at a loss, and hope you can help before I conclude that wxWidgets does not contain the functionality I've found Java provide very easily with its JPanel, Graphics, BufferedImage and Thread classes.

I am happy to post further code examples, but didn't know what parts of this system you'd like to see - there are several classes derived from the wxWidgets framework.

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 361
Joined: Tue Jun 20, 2006 6:47 pm

Re: Real-time Graphical Output on a wxPanel from within a wxThread

Post by New Pagodi » Tue May 19, 2020 5:49 pm

As the documentation states:
When writing a multi-threaded application, it is strongly recommended that no secondary threads call GUI functions.
What you can do is throw an event from your secondary thread and then in the handler for that event call Update/Refresh on the panel. The page for wxThread gives and example of how to do throw the event from the secondary thread.

Part Of The Furniture
Part Of The Furniture
Posts: 2672
Joined: Sun Jan 03, 2010 5:45 pm

Re: Real-time Graphical Output on a wxPanel from within a wxThread

Post by PB » Tue May 19, 2020 5:52 pm

There is little reason to actually draw from the secondary thread.

As NewPagodi wrote, you can collect and prepare data In the worker thread and then tell the main thread it is time to redraw.

Post Reply