News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Drawing on wxPanel outside the evt_paint.

Started by nishalns, July 26, 2013, 06:23:42 AM

Previous topic - Next topic

nishalns

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?

stahta01

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++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

ollydbg

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.

nishalns

#3
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