wxGLCanvas Pause Paint Event? Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
rajan_m
Knows some wx things
Knows some wx things
Posts: 39
Joined: Tue Jan 20, 2009 10:37 am
Location: chennai

wxGLCanvas Pause Paint Event?

Post by rajan_m » Wed Nov 05, 2014 8:15 am

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.
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!

User avatar
doublemax
Moderator
Moderator
Posts: 14772
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGLCanvas Pause Paint Event?

Post by doublemax » Wed Nov 05, 2014 9:52 am

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.
Use the source, Luke!

rajan_m
Knows some wx things
Knows some wx things
Posts: 39
Joined: Tue Jan 20, 2009 10:37 am
Location: chennai

Re: wxGLCanvas Pause Paint Event?

Post by rajan_m » Wed Nov 05, 2014 11:00 am

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.
Every exit is an entry somewhere else!

User avatar
doublemax
Moderator
Moderator
Posts: 14772
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGLCanvas Pause Paint Event?

Post by doublemax » Wed Nov 05, 2014 11:58 am

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.
Use the source, Luke!

Manolo
Can't get richer than this
Can't get richer than this
Posts: 712
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxGLCanvas Pause Paint Event?

Post by Manolo » Wed Nov 05, 2014 2:24 pm

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.

rajan_m
Knows some wx things
Knows some wx things
Posts: 39
Joined: Tue Jan 20, 2009 10:37 am
Location: chennai

Re: wxGLCanvas Pause Paint Event?

Post by rajan_m » Thu Nov 06, 2014 10:58 am

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.
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!

rajan_m
Knows some wx things
Knows some wx things
Posts: 39
Joined: Tue Jan 20, 2009 10:37 am
Location: chennai

Re: wxGLCanvas Pause Paint Event?

Post by rajan_m » Thu Nov 06, 2014 11:10 am

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.
Every exit is an entry somewhere else!

User avatar
doublemax
Moderator
Moderator
Posts: 14772
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxGLCanvas Pause Paint Event?

Post by doublemax » Thu Nov 06, 2014 11:33 am

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.
Use the source, Luke!

Post Reply