]> git.saurik.com Git - wxWidgets.git/commitdiff
don't crash if an image is not found
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 14 Apr 2003 00:46:59 +0000 (00:46 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 14 Apr 2003 00:46:59 +0000 (00:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20208 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/image/image.cpp

index 3565381acf7e2d85a977e3d242717872d0b07c49..6c96a7505b54e83188f39c4770e99155c1022441 100644 (file)
@@ -406,8 +406,8 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
 
     image.Destroy();
 
-    image.LoadFile( dir + _T("test.png") );
-    my_square = new wxBitmap( image );
+    if ( image.LoadFile( dir + _T("test.png") ) )
+        my_square = new wxBitmap( image );
 
     image.Destroy();
 
@@ -549,20 +549,23 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
 
     // test image loading from stream
     wxFile file(dir + _T("horse.bmp"));
-    off_t len = file.Length();
-    void *data = malloc(len);
-    if ( file.Read(data, len) != len )
-        wxLogError(_T("Reading bitmap file failed"));
-    else
+    if ( file.IsOpened() )
     {
-        wxMemoryInputStream mis(data, len);
-        if ( !image.LoadFile(mis) )
-            wxLogError(wxT("Can't load BMP image from stream"));
+        off_t len = file.Length();
+        void *data = malloc(len);
+        if ( file.Read(data, len) != len )
+            wxLogError(_T("Reading bitmap file failed"));
         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()