Hi,
In a application with data shared between wxGLCanvas and wxThreads.
Scenario : thread modifies the data which is used by canvas which results in a crash in paint event.
Current Solution : used mutex to share the data between canvas and thread.
Issue: we are displaying progress info of thread in a dialog. mutex locks (in canvas paint event) main thread and the progress info dialog hangs.
Correction : canvas paint event is triggered multiple times which leads to multiple mutex lock calls , which leads to UI hang.
Any solution for my issue are highly appreciated.
wxGLCanvas Pause Paint Event? Topic is solved
wxGLCanvas Pause Paint Event?
Last edited by rajan_m on Thu Nov 06, 2014 11:05 am, edited 1 time in total.
Every exit is an entry somewhere else!
Re: wxGLCanvas Pause Paint Event?
Does the calculation of the new data take so long?
If yes, i see two solutions:
1) In the paint event handler you just clear the DC instead of rendering the data (or display some text)
2) You keep a copy of the old data and display that as long as the calculation is not finished.
If yes, i see two solutions:
1) In the paint event handler you just clear the DC instead of rendering the data (or display some text)
2) You keep a copy of the old data and display that as long as the calculation is not finished.
Use the source, Luke!
Re: wxGLCanvas Pause Paint Event?
Hi doublemax,
I forgot to mention our data is huge and copying is costly work. And we are also not allowed to clear or change the canvas content.
Thanks for your reply.
I forgot to mention our data is huge and copying is costly work. And we are also not allowed to clear or change the canvas content.
Thanks for your reply.
Every exit is an entry somewhere else!
Re: wxGLCanvas Pause Paint Event?
The only other option i could think of would be to display a static bitmap of the old content.I forgot to mention our data is huge and copying is costly work. And we are also not allowed to clear or change the canvas content.
Use the source, Luke!
Re: wxGLCanvas Pause Paint Event?
Reading data so you can draw it and at the same time modifying that data is bad.
Making a thread to lock the GUI is also bad.
If you can't use doublemax's proposals, I would break the data into chunks. While the working thread modify one chunk, the GUI reads and draws other chunk. When a chunk is done in the thread, it posts a message to GUI so it can operate with that chunk.
Making a thread to lock the GUI is also bad.
If you can't use doublemax's proposals, I would break the data into chunks. While the working thread modify one chunk, the GUI reads and draws other chunk. When a chunk is done in the thread, it posts a message to GUI so it can operate with that chunk.
Re: wxGLCanvas Pause Paint Event?
Simple solution , but I'm curious to solve my mutex problem. please see my update in the question.doublemax wrote:The only other option i could think of would be to display a static bitmap of the old content.I forgot to mention our data is huge and copying is costly work. And we are also not allowed to clear or change the canvas content.
Last edited by rajan_m on Thu Nov 06, 2014 11:11 am, edited 1 time in total.
Every exit is an entry somewhere else!
Re: wxGLCanvas Pause Paint Event?
Thanks for your reply, we cannot draw partial data and canvas draw is way faster than our thread function execution.Manolo wrote: I would break the data into chunks. While the working thread modify one chunk, the GUI reads and draws other chunk..
Every exit is an entry somewhere else!
Re: wxGLCanvas Pause Paint Event?
There is no solution for this. Your program should be able to respond to a paint event at any given time. If the paint event handler has to wait, because the data is not ready, the program will block.Simple solution , but I'm curious to solve my mutex problem. please see my update in the question.
Mutexes under Windows are not recursive. Use TryLock instead of Lock and just exit the paint event handler if the mutex is already locked. Of course this will lead to redraw errors.
Use the source, Luke!