Author Topic: Drawing on wxPanel outside the evt_paint.  (Read 5417 times)

Offline nishalns

  • Multiple posting newcomer
  • *
  • Posts: 22
Drawing on wxPanel outside the evt_paint.
« on: July 26, 2013, 06:23:42 am »
Actually, i'm creating a simulator type application. Now, there is a panel called 'drawingPanel' on which they simulation takes place. Now, in my program I want to paint on this panel with another thread, 'simulationThread'. But when I try to paint on the panel from inside the Entry() function of the thread using wxDC, I get a "wx debug alert" message box, saying
Quote
../../src/msw/dcclient.cpp(222):assert "Assert failure" failed in wxPaintDCImpl(): wxPaintDCImpl may be only created in EVT_PAINT handler! [in thread e0]

Do you want to stop the program?

You can also choose [cancel] to suppress further warnings.

And the program execution stops.

I do understand what the error message means, but I don't know how to fix it. Can somebody help?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6800
    • My Best Post
Re: Drawing on wxPanel outside the evt_paint.
« Reply #1 on: July 26, 2013, 07:09:18 am »
If this is wxWidgets version 2.9 or higher please ask in the wxWidgets forum.

http://forums.wxwidgets.org/

If not, please state Compiler, Code::Blocks, and wxWidgets version info.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5229
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Drawing on wxPanel outside the evt_paint.
« Reply #2 on: July 26, 2013, 07:09:30 am »
This is a wxWidgets related question, so it is not related to C::B, so your topic may be locked.
But I can give you some direction:
1, it is generally not a good idea to draw GUI from a worker thread.

2, "wxPaintDCImpl may be only created in EVT_PAINT handler", you can't use wxPaintDC here, maybe you should try wxClientDC or other things I don't know.

3, http://forums.wxwidgets.org/ is a good place to ask.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline nishalns

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: Drawing on wxPanel outside the evt_paint.
« Reply #3 on: July 26, 2013, 07:36:46 am »
Thanks all for your replies especially "ollydbg". I was actually using wxPaintDC and i changed to wxClientDC and wollah! it worked! Thank you very much.... ;D
« Last Edit: July 26, 2013, 07:49:11 am by nishalns »