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.
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".
wxFAIL_MSG( wxT("wxPaintDCImpl may be created only in EVT_PAINT handler!") );
We should use a wxClientDC to draw something in OnEraseBackground.
See this page:
http://www.informit.com/articles/article.aspx?p=405047
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:
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))