Author Topic: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues  (Read 7677 times)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
This thread for small patches to fix CB Runtime crashes/error logging when linked wxWidgets 3.0.

Half of the time it crashes on startup when linked against wxWidgets 3.0 branch.

Tim S.

Code
Index: src/src/splashscreen.cpp
===================================================================
--- src/src/splashscreen.cpp (revision 9506)
+++ src/src/splashscreen.cpp (working copy)
@@ -99,10 +99,12 @@
 
 void cbSplashScreen::OnEraseBackground(wxEraseEvent &event)
 {
+#if !wxCHECK_VERSION(3, 0, 0)
     wxDC *dc = event.GetDC();
 
     if (dc)
         DoPaint(*dc); // why not? :)
+#endif
 }
 
 void cbSplashScreen::OnTimer(wxTimerEvent &)

The message you get if it does not crash is from the next line in file "src/msw/dcclient.cpp".
Code
wxFAIL_MSG( wxT("wxPaintDCImpl may be created only in EVT_PAINT handler!") );
« Last Edit: December 29, 2013, 10:29:35 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
« Reply #1 on: December 29, 2013, 06:00:00 pm »
The question is do we really need the erase background event. What is its purpose?
It seems to work fine without it on wxGTK 2.8.
« Last Edit: December 29, 2013, 06:01:40 pm by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Re: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
« Reply #2 on: December 29, 2013, 08:09:22 pm »
The question is do we really need the erase background event. What is its purpose?
It seems to work fine without it on wxGTK 2.8.

I would guess its NOT needed; but, I am not an wxWidgets expert, so it is really just a guess.

Tim S.
 
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
« Reply #3 on: December 29, 2013, 08:23:27 pm »
I would guess its NOT needed; but, I am not an wxWidgets expert, so it is really just a guess.
Yes, I think so, too (not needed).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
« Reply #4 on: December 30, 2013, 03:02:36 am »
We should use a wxClientDC to draw something in OnEraseBackground.
See this page:
http://www.informit.com/articles/article.aspx?p=405047

Code:
Code
BEGIN_EVENT_TABLE(MyWindow, wxWindow)
  EVT_ERASE_BACKGROUND(MyWindow::OnErase)
END_EVENT_TABLE()

void MyWindow::OnErase(wxEraseEvent& event)
{
    wxClientDC* clientDC = NULL;
    if (!event.GetDC())
        clientDC = new wxClientDC(this);

    wxDC* dc = clientDC ? clientDC : event.GetDC() ;

    wxSize sz = GetClientSize();
    wxEffects effects;
    effects.TileBitmap(wxRect(0, 0, sz.x, sz.y), *dc, m_bitmap);

    if (clientDC)
        delete clientDC;
}

So, it is wrong to call DoPaint() here which receive a wrong wxClientDC instance.

Another issue is:

Code
void cbSplashScreen::OnPaint(wxPaintEvent &)
{
    // an obscure statement in the wxWidgets book says to
    // allocate the DC even if you don't paint to avoid
    // a paint loop.    //pecan 2006/04/3
    wxPaintDC paint_dc(this);
    DoPaint(paint_dc);
}

void cbSplashScreen::OnEraseBackground(wxEraseEvent &event)
{
    wxDC *dc = event.GetDC();

    if (dc)
        DoPaint(*dc); // why not? :)
}

I think usually erase background event is happened before paint event, so we always paint the screen twice? So, I think we can leave the OnEraseBackground function body empty, this can also avoid flickering (see: Flicker-Free Drawing - WxWiki)

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.