Check for self=nil before processing in init

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/branches/gnustep_testplant_branch@36603 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2013-05-09 01:32:02 +00:00
parent acf6d13308
commit 612a141f28

View file

@ -146,100 +146,103 @@
- (id) initWithDevice: (void *)device
{
// Save/set initial state...
gsDevice = device;
_surface = NULL;
WIN_INTERN *win = (WIN_INTERN *)GetWindowLong(GSWINDEVICE, GWL_USERDATA);
HDC hDC = GetDC(GSWINDEVICE);
if (hDC == NULL)
if (self)
{
NSWarnMLog(@"Win32CairoSurface line: %d : no device context", __LINE__);
// Save/set initial state...
gsDevice = device;
_surface = NULL;
// And deallocate ourselves...
DESTROY(self);
}
else
{
// Create the cairo surfaces...
// NSBackingStoreRetained works like Buffered since 10.5 (See apple docs)...
// NOTE: According to Apple docs NSBackingStoreBuffered should be the only one
// ever used anymore....others are NOT recommended...
if (win && (win->type == NSBackingStoreNonretained))
WIN_INTERN *win = (WIN_INTERN *)GetWindowLong(GSWINDEVICE, GWL_USERDATA);
HDC hDC = GetDC(GSWINDEVICE);
if (hDC == NULL)
{
// This is the raw DC surface...
_surface = cairo_win32_surface_create(hDC);
NSWarnMLog(@"Win32CairoSurface line: %d : no device context", __LINE__);
// Check for error...
if (cairo_surface_status(_surface) != CAIRO_STATUS_SUCCESS)
{
// Output the surface create error...
cairo_status_t status = cairo_surface_status(_surface);
NSWarnMLog(@"surface create FAILED - status: %s\n", cairo_status_to_string(status));
// Destroy the initial surface created...
cairo_surface_destroy(_surface);
// And deallocate ourselves...
DESTROY(self);
}
// And deallocate ourselves...
DESTROY(self);
}
else
{
NSSize csize = [self size];
// This is the raw DC surface...
cairo_surface_t *window = cairo_win32_surface_create(hDC);
// Check for error...
if (cairo_surface_status(window) != CAIRO_STATUS_SUCCESS)
// Create the cairo surfaces...
// NSBackingStoreRetained works like Buffered since 10.5 (See apple docs)...
// NOTE: According to Apple docs NSBackingStoreBuffered should be the only one
// ever used anymore....others are NOT recommended...
if (win && (win->type == NSBackingStoreNonretained))
{
// Output the surface create error...
cairo_status_t status = cairo_surface_status(window);
NSWarnMLog(@"surface create FAILED - status: %s\n", cairo_status_to_string(status));
// And deallocate ourselves...
DESTROY(self);
}
else
{
// and this is the in-memory DC surface...surface owns its DC...
// NOTE: For some reason we get an init sequence with zero width/height,
// which creates problems in the cairo layer. It tries to clear
// the 'similar' surface it's creating, and with a zero width/height
// it incorrectly thinks the clear failed...so we will init with
// a minimum size of 1 for width/height...
_surface = cairo_surface_create_similar(window, CAIRO_CONTENT_COLOR_ALPHA,
MAX(1, csize.width),
MAX(1, csize.height));
// This is the raw DC surface...
_surface = cairo_win32_surface_create(hDC);
// Check for error...
if (cairo_surface_status(_surface) != CAIRO_STATUS_SUCCESS)
{
// Output the surface create error...
cairo_status_t status = cairo_surface_status(_surface);
NSWarnMLog(@"surface create FAILED - status: %s\n", cairo_status_to_string(status));
NSWarnMLog(@"surface create FAILED - status: %s\n", cairo_status_to_string(status));
// Destroy the surface created...
// Destroy the initial surface created...
cairo_surface_destroy(_surface);
// And deallocate ourselves...
DESTROY(self);
}
}
else
{
NSSize csize = [self size];
// Destroy the initial surface created...
cairo_surface_destroy(window);
// This is the raw DC surface...
cairo_surface_t *window = cairo_win32_surface_create(hDC);
// Release the device context...
ReleaseDC(GSWINDEVICE, hDC);
}
// Check for error...
if (cairo_surface_status(window) != CAIRO_STATUS_SUCCESS)
{
// Output the surface create error...
cairo_status_t status = cairo_surface_status(window);
NSWarnMLog(@"surface create FAILED - status: %s\n", cairo_status_to_string(status));
if (self)
{
// We need this for handleExposeEvent in WIN32Server...
win->surface = (void*)self;
// And deallocate ourselves...
DESTROY(self);
}
else
{
// and this is the in-memory DC surface...surface owns its DC...
// NOTE: For some reason we get an init sequence with zero width/height,
// which creates problems in the cairo layer. It tries to clear
// the 'similar' surface it's creating, and with a zero width/height
// it incorrectly thinks the clear failed...so we will init with
// a minimum size of 1 for width/height...
_surface = cairo_surface_create_similar(window, CAIRO_CONTENT_COLOR_ALPHA,
MAX(1, csize.width),
MAX(1, csize.height));
// Check for error...
if (cairo_surface_status(_surface) != CAIRO_STATUS_SUCCESS)
{
// Output the surface create error...
cairo_status_t status = cairo_surface_status(_surface);
NSWarnMLog(@"surface create FAILED - status: %s\n", cairo_status_to_string(status));
// Destroy the surface created...
cairo_surface_destroy(_surface);
// And deallocate ourselves...
DESTROY(self);
}
}
// Destroy the initial surface created...
cairo_surface_destroy(window);
// Release the device context...
ReleaseDC(GSWINDEVICE, hDC);
}
if (self)
{
// We need this for handleExposeEvent in WIN32Server...
win->surface = (void*)self;
}
}
}
return self;