Avoid crash in wxBitmap::GetImage() for invalid bitmaps
Just return NULL from this (wxOSX private, in spite of not using a port-specific prefix) method. This fixes crash in wxButton::SetBitmapXXX(wxNullBitmap), as shown by the new test case which used to crash but doesn't do it any longer. Closes #19257.
This commit is contained in:
@@ -204,6 +204,7 @@ public:
|
|||||||
// returns a CGImageRef which must released after usage with CGImageRelease
|
// returns a CGImageRef which must released after usage with CGImageRelease
|
||||||
CGImageRef CreateCGImage() const ;
|
CGImageRef CreateCGImage() const ;
|
||||||
|
|
||||||
|
// returns nil for invalid bitmap
|
||||||
WXImage GetImage() const;
|
WXImage GetImage() const;
|
||||||
#if wxOSX_USE_COCOA
|
#if wxOSX_USE_COCOA
|
||||||
// returns an autoreleased version of the image
|
// returns an autoreleased version of the image
|
||||||
|
@@ -951,7 +951,7 @@ bool wxBitmap::Create(CGContextRef bitmapcontext)
|
|||||||
|
|
||||||
WXImage wxBitmap::GetImage() const
|
WXImage wxBitmap::GetImage() const
|
||||||
{
|
{
|
||||||
return GetBitmapData()->GetImage();
|
return IsOk() ? GetBitmapData()->GetImage() : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
|
||||||
|
@@ -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).
|
// updating the bitmap later, as it used to be the case in wxGTK (#18898).
|
||||||
m_button->SetLabel(wxString());
|
m_button->SetLabel(wxString());
|
||||||
CHECK_NOTHROW( m_button->Disable() );
|
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
|
#endif //wxUSE_BUTTON
|
||||||
|
Reference in New Issue
Block a user