guarding agains NULL

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2012-06-14 21:51:19 +00:00
parent 7d5b794ce4
commit f5fac4471b

View File

@@ -1035,8 +1035,10 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
{ {
unsigned char *sourcedata = (unsigned char*) GetRawAccess() ; unsigned char *sourcedata = (unsigned char*) GetRawAccess() ;
unsigned char *destdata = (unsigned char*) ret.BeginRawAccess() ; unsigned char *destdata = (unsigned char*) ret.BeginRawAccess() ;
wxASSERT( (sourcedata != NULL) && (destdata != NULL) ) ; wxASSERT((sourcedata != NULL) && (destdata != NULL));
if ( (sourcedata != NULL) && (destdata != NULL) )
{
int sourcelinesize = GetBitmapData()->GetBytesPerRow() ; int sourcelinesize = GetBitmapData()->GetBytesPerRow() ;
int destlinesize = ret.GetBitmapData()->GetBytesPerRow() ; int destlinesize = ret.GetBitmapData()->GetBytesPerRow() ;
unsigned char *source = sourcedata + rect.x * 4 + rect.y * sourcelinesize ; unsigned char *source = sourcedata + rect.x * 4 + rect.y * sourcelinesize ;
@@ -1047,8 +1049,9 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
memcpy( dest , source , destlinesize ) ; memcpy( dest , source , destlinesize ) ;
} }
} }
ret.EndRawAccess() ; ret.EndRawAccess() ;
}
if ( M_BITMAPDATA->m_bitmapMask ) if ( M_BITMAPDATA->m_bitmapMask )
{ {
@@ -1063,6 +1066,8 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
unsigned char *destdata = (unsigned char * ) maskbuf.GetWriteBuf( maskbufsize ) ; unsigned char *destdata = (unsigned char * ) maskbuf.GetWriteBuf( maskbufsize ) ;
wxASSERT( (source != NULL) && (destdata != NULL) ) ; wxASSERT( (source != NULL) && (destdata != NULL) ) ;
if ( (source != NULL) && (destdata != NULL) )
{
source += rect.x * kMaskBytesPerPixel + rect.y * sourcelinesize ; source += rect.x * kMaskBytesPerPixel + rect.y * sourcelinesize ;
unsigned char *dest = destdata ; unsigned char *dest = destdata ;
@@ -1072,6 +1077,7 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
} }
maskbuf.UngetWriteBuf( maskbufsize ) ; maskbuf.UngetWriteBuf( maskbufsize ) ;
}
ret.SetMask( new wxMask( maskbuf , destwidth , destheight , rowBytes ) ) ; ret.SetMask( new wxMask( maskbuf , destwidth , destheight , rowBytes ) ) ;
} }
else if ( HasAlpha() ) else if ( HasAlpha() )
@@ -1607,7 +1613,8 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
size_t size = m_bytesPerRow * m_height ; size_t size = m_bytesPerRow * m_height ;
unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ; unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
wxASSERT( destdatabase != NULL ) ; wxASSERT( destdatabase != NULL ) ;
if ( destdatabase != NULL)
{
memset( destdatabase , 0 , size ) ; memset( destdatabase , 0 , size ) ;
unsigned char * srcdatabase = (unsigned char*) bitmap.GetRawAccess() ; unsigned char * srcdatabase = (unsigned char*) bitmap.GetRawAccess() ;
size_t sourceBytesRow = bitmap.GetBitmapData()->GetBytesPerRow(); size_t sourceBytesRow = bitmap.GetBitmapData()->GetBytesPerRow();
@@ -1631,7 +1638,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
*destdata++ = 0x00 ; *destdata++ = 0x00 ;
} }
} }
}
m_memBuf.UngetWriteBuf( size ) ; m_memBuf.UngetWriteBuf( size ) ;
RealizeNative() ; RealizeNative() ;