From aaa9782834fbbbdc1d6a58766602ba40ea4121ef Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 11 May 2003 00:59:42 +0000 Subject: [PATCH] wxImage::Create() should be bool, not void git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20578 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/image.h | 4 ++-- src/common/image.cpp | 43 +++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/include/wx/image.h b/include/wx/image.h index 62e50e8cd1..12a0223cc7 100644 --- a/include/wx/image.h +++ b/include/wx/image.h @@ -162,8 +162,8 @@ public: #endif #endif - void Create( int width, int height, bool clear = true ); - void Create( int width, int height, unsigned char* data, bool static_data = FALSE ); + bool Create( int width, int height, bool clear = true ); + bool Create( int width, int height, unsigned char* data, bool static_data = FALSE ); void Destroy(); // creates an identical copy of the image (the = operator diff --git a/src/common/image.cpp b/src/common/image.cpp index cccfe9f1bf..98daf43393 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -156,45 +156,44 @@ wxImage::wxImage( const wxImage* image ) if (image) Ref(*image); } -void wxImage::Create( int width, int height, bool clear ) +bool wxImage::Create( int width, int height, bool clear ) { UnRef(); m_refData = new wxImageRefData(); M_IMGDATA->m_data = (unsigned char *) malloc( width*height*3 ); - if (M_IMGDATA->m_data) - { - if (clear) memset(M_IMGDATA->m_data, 0, width*height*3); - - M_IMGDATA->m_width = width; - M_IMGDATA->m_height = height; - M_IMGDATA->m_ok = TRUE; - } - else + if (!M_IMGDATA->m_data) { UnRef(); + return FALSE; } + + if (clear) + memset(M_IMGDATA->m_data, 0, width*height*3); + + M_IMGDATA->m_width = width; + M_IMGDATA->m_height = height; + M_IMGDATA->m_ok = TRUE; + + return TRUE; } -void wxImage::Create( int width, int height, unsigned char* data, bool static_data ) +bool wxImage::Create( int width, int height, unsigned char* data, bool static_data ) { UnRef(); + wxCHECK_MSG( data, FALSE, _T("NULL data in wxImage::Create") ); + m_refData = new wxImageRefData(); M_IMGDATA->m_data = data; - if (M_IMGDATA->m_data) - { - M_IMGDATA->m_width = width; - M_IMGDATA->m_height = height; - M_IMGDATA->m_ok = TRUE; - M_IMGDATA->m_static = static_data; - } - else - { - UnRef(); - } + M_IMGDATA->m_width = width; + M_IMGDATA->m_height = height; + M_IMGDATA->m_ok = TRUE; + M_IMGDATA->m_static = static_data; + + return TRUE; } void wxImage::Destroy() -- 2.45.2