Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: stahta01 on December 29, 2013, 10:23:21 am

Title: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
Post by: stahta01 on December 29, 2013, 10:23:21 am
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!") );
Title: Re: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
Post by: oBFusCATed 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.
Title: Re: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
Post by: stahta01 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.
 
Title: Re: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
Post by: MortenMacFly 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).
Title: Re: Patches for Code::Blocks linked with wxWidgets 3.0 Runtime issues
Post by: ollydbg 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 (http://wiki.wxwidgets.org/Flicker-Free_Drawing))