safeguard against not-yet-shown view which leads to crashes under OSX

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67167 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2011-03-10 18:55:55 +00:00
parent 89c6e02442
commit bda7c3535e

View File

@@ -371,14 +371,16 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
int width = subrect != NULL ? subrect->width : sz.x; int width = subrect != NULL ? subrect->width : sz.x;
int height = subrect != NULL ? subrect->height : sz.y ; int height = subrect != NULL ? subrect->height : sz.y ;
wxBitmap bitmap(width, height);
NSView* view = (NSView*) m_window->GetHandle(); NSView* view = (NSView*) m_window->GetHandle();
if ( [view isHiddenOrHasHiddenAncestor] == NO )
{
[view lockFocus]; [view lockFocus];
// we use this method as other methods force a repaint, and this method can be // we use this method as other methods force a repaint, and this method can be
// called from OnPaint, even with the window's paint dc as source (see wxHTMLWindow) // called from OnPaint, even with the window's paint dc as source (see wxHTMLWindow)
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]] retain]; NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]] retain];
[view unlockFocus]; [view unlockFocus];
wxBitmap bitmap(width, height);
if ( [rep respondsToSelector:@selector(CGImage)] ) if ( [rep respondsToSelector:@selector(CGImage)] )
{ {
CGImageRef cgImageRef = (CGImageRef)[rep CGImage]; CGImageRef cgImageRef = (CGImageRef)[rep CGImage];
@@ -394,6 +396,7 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
// TODO for 10.4 in case we can support this for osx_cocoa // TODO for 10.4 in case we can support this for osx_cocoa
} }
[rep release]; [rep release];
}
return bitmap; return bitmap;
} }