Always create wxStaticBitmap in the widgets sample
Not creating it when the default image wasn't found resulted in a crash, so always create wxStaticBitmap using a fallback bitmap if necessary. Also add a wxCHECK_RET to prevent the crash from happening in a similar situation in the future.
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include "wx/textctrl.h"
|
||||
#endif
|
||||
|
||||
#include "wx/artprov.h"
|
||||
#include "wx/filename.h"
|
||||
|
||||
#include "wx/generic/statbmpg.h"
|
||||
@@ -126,28 +127,39 @@ void StatBmpWidgetsPage::RecreateWidget()
|
||||
{
|
||||
wxDELETE(m_statbmp);
|
||||
|
||||
wxString filepath = m_filepicker->GetPath();
|
||||
if ( filepath.empty() )
|
||||
return;
|
||||
wxBitmap bmp;
|
||||
|
||||
wxString filepath = m_filepicker->GetPath();
|
||||
if ( !filepath.empty() )
|
||||
{
|
||||
wxImage image(filepath);
|
||||
if (! image.IsOk() )
|
||||
if ( image.IsOk() )
|
||||
{
|
||||
bmp = image;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogMessage("Reading image from file '%s' failed.", filepath.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !bmp.IsOk() )
|
||||
{
|
||||
// Show at least something.
|
||||
bmp = wxArtProvider::GetBitmap(wxART_MISSING_IMAGE);
|
||||
}
|
||||
|
||||
long style = GetAttrs().m_defaultFlags;
|
||||
|
||||
if (m_radio->GetSelection() == 0)
|
||||
{
|
||||
m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(image),
|
||||
m_statbmp = new wxStaticBitmap(this, wxID_ANY, bmp,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
style);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_statbmp = new wxGenericStaticBitmap(this, wxID_ANY, wxBitmap(image),
|
||||
m_statbmp = new wxGenericStaticBitmap(this, wxID_ANY, bmp,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
style);
|
||||
}
|
||||
|
@@ -680,8 +680,11 @@ void WidgetsFrame::ConnectToWidgetEvents()
|
||||
it != widgets.end();
|
||||
++it )
|
||||
{
|
||||
(*it)->Bind(wxEVT_SET_FOCUS, &WidgetsFrame::OnWidgetFocus, this);
|
||||
(*it)->Bind(wxEVT_KILL_FOCUS, &WidgetsFrame::OnWidgetFocus, this);
|
||||
wxWindow* const w = *it;
|
||||
wxCHECK_RET(w, "NULL widget");
|
||||
|
||||
w->Bind(wxEVT_SET_FOCUS, &WidgetsFrame::OnWidgetFocus, this);
|
||||
w->Bind(wxEVT_KILL_FOCUS, &WidgetsFrame::OnWidgetFocus, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user