don't crash if an image is not found

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20208 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-04-14 00:46:59 +00:00
parent 4455332266
commit 30ad0a1469

View File

@@ -406,8 +406,8 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
image.Destroy(); image.Destroy();
image.LoadFile( dir + _T("test.png") ); if ( image.LoadFile( dir + _T("test.png") ) )
my_square = new wxBitmap( image ); my_square = new wxBitmap( image );
image.Destroy(); image.Destroy();
@@ -549,20 +549,23 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
// test image loading from stream // test image loading from stream
wxFile file(dir + _T("horse.bmp")); wxFile file(dir + _T("horse.bmp"));
off_t len = file.Length(); if ( file.IsOpened() )
void *data = malloc(len);
if ( file.Read(data, len) != len )
wxLogError(_T("Reading bitmap file failed"));
else
{ {
wxMemoryInputStream mis(data, len); off_t len = file.Length();
if ( !image.LoadFile(mis) ) void *data = malloc(len);
wxLogError(wxT("Can't load BMP image from stream")); if ( file.Read(data, len) != len )
wxLogError(_T("Reading bitmap file failed"));
else else
my_horse_bmp2 = new wxBitmap( image ); {
} wxMemoryInputStream mis(data, len);
if ( !image.LoadFile(mis) )
wxLogError(wxT("Can't load BMP image from stream"));
else
my_horse_bmp2 = new wxBitmap( image );
}
free(data); free(data);
}
} }
MyCanvas::~MyCanvas() MyCanvas::~MyCanvas()