diff --git a/include/wx/osx/bitmap.h b/include/wx/osx/bitmap.h index d1388a85fb..6484a5e7e2 100644 --- a/include/wx/osx/bitmap.h +++ b/include/wx/osx/bitmap.h @@ -204,6 +204,7 @@ public: // returns a CGImageRef which must released after usage with CGImageRelease CGImageRef CreateCGImage() const ; + // returns nil for invalid bitmap WXImage GetImage() const; #if wxOSX_USE_COCOA // returns an autoreleased version of the image diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index cb9f2163e3..b4e8163c6f 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -951,7 +951,7 @@ bool wxBitmap::Create(CGContextRef bitmapcontext) WXImage wxBitmap::GetImage() const { - return GetBitmapData()->GetImage(); + return IsOk() ? GetBitmapData()->GetImage() : NULL; } wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const diff --git a/tests/controls/buttontest.cpp b/tests/controls/buttontest.cpp index c6a5725646..4a13623a6d 100644 --- a/tests/controls/buttontest.cpp +++ b/tests/controls/buttontest.cpp @@ -160,6 +160,11 @@ TEST_CASE_METHOD(ButtonTestCase, "Button::Bitmap", "[button]") // updating the bitmap later, as it used to be the case in wxGTK (#18898). m_button->SetLabel(wxString()); CHECK_NOTHROW( m_button->Disable() ); + + // Also check that setting an invalid bitmap doesn't do anything untoward, + // such as crashing, as it used to do in wxOSX (#19257). + CHECK_NOTHROW( m_button->SetBitmapPressed(wxNullBitmap) ); + CHECK( !m_button->GetBitmapPressed().IsOk() ); } #endif //wxUSE_BUTTON