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,29 +371,32 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
int width = subrect != NULL ? subrect->width : sz.x;
int height = subrect != NULL ? subrect->height : sz.y ;
NSView* view = (NSView*) m_window->GetHandle();
[view lockFocus];
// 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)
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]] retain];
[view unlockFocus];
wxBitmap bitmap(width, height);
if ( [rep respondsToSelector:@selector(CGImage)] )
{
CGImageRef cgImageRef = (CGImageRef)[rep CGImage];
CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
// since our context is upside down we dont use CGContextDrawImage
wxMacDrawCGImage( (CGContextRef) bitmap.GetHBITMAP() , &r, cgImageRef ) ;
CGImageRelease(cgImageRef);
cgImageRef = NULL;
}
else
NSView* view = (NSView*) m_window->GetHandle();
if ( [view isHiddenOrHasHiddenAncestor] == NO )
{
// TODO for 10.4 in case we can support this for osx_cocoa
[view lockFocus];
// 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)
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]] retain];
[view unlockFocus];
if ( [rep respondsToSelector:@selector(CGImage)] )
{
CGImageRef cgImageRef = (CGImageRef)[rep CGImage];
CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) );
// since our context is upside down we dont use CGContextDrawImage
wxMacDrawCGImage( (CGContextRef) bitmap.GetHBITMAP() , &r, cgImageRef ) ;
CGImageRelease(cgImageRef);
cgImageRef = NULL;
}
else
{
// TODO for 10.4 in case we can support this for osx_cocoa
}
[rep release];
}
[rep release];
return bitmap;
}