Page 1 of 1

wxGLCanvas Pause Paint Event?

Posted: Wed Nov 05, 2014 8:15 am
by rajan_m
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.

Re: wxGLCanvas Pause Paint Event?

Posted: Wed Nov 05, 2014 9:52 am
by doublemax
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.

Re: wxGLCanvas Pause Paint Event?

Posted: Wed Nov 05, 2014 11:00 am
by rajan_m
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.

Re: wxGLCanvas Pause Paint Event?

Posted: Wed Nov 05, 2014 11:58 am
by 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.
The only other option i could think of would be to display a static bitmap of the old content.

Re: wxGLCanvas Pause Paint Event?

Posted: Wed Nov 05, 2014 2:24 pm
by Manolo
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.

Re: wxGLCanvas Pause Paint Event?

Posted: Thu Nov 06, 2014 10:58 am
by rajan_m
doublemax wrote:
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.
The only other option i could think of would be to display a static bitmap of the old content.
Simple solution , but I'm curious to solve my mutex problem. please see my update in the question.

Re: wxGLCanvas Pause Paint Event?

Posted: Thu Nov 06, 2014 11:10 am
by rajan_m
Manolo wrote: I would break the data into chunks. While the working thread modify one chunk, the GUI reads and draws other chunk..
Thanks for your reply, we cannot draw partial data and canvas draw is way faster than our thread function execution.

Re: wxGLCanvas Pause Paint Event?

Posted: Thu Nov 06, 2014 11:33 am
by doublemax
Simple solution , but I'm curious to solve my mutex problem. please see my update in the question.
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.

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.