* Source/NSImage.m (_cacheForRep:): Don't assume rep is non-nil. This should fix

locking focus on an image with no representations.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33827 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ericwa 2011-09-09 19:49:08 +00:00
parent af8edd509c
commit 0ef27026f5
2 changed files with 36 additions and 18 deletions

View file

@ -1,3 +1,8 @@
2011-09-09 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSImage.m (_cacheForRep:): Don't assume rep is non-nil. This should fix
locking focus on an image with no representations.
2011-09-08 Gregory Casamento <greg.casamento@gmail.com> 2011-09-08 Gregory Casamento <greg.casamento@gmail.com>
* Source/NSImage.m: Correction for call to function NSEqualSizes. * Source/NSImage.m: Correction for call to function NSEqualSizes.

View file

@ -2054,14 +2054,15 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
NSImageRep *cacheRep = nil; NSImageRep *cacheRep = nil;
GSRepData *repd; GSRepData *repd;
NSSize imageSize = [self size]; NSSize imageSize = [self size];
NSSize repSize = [rep size]; NSSize repSize;
int pixelsWide, pixelsHigh; int pixelsWide, pixelsHigh;
if (repSize.width == 0 || repSize.height == 0) if (rep != nil)
repSize = imageSize; {
repSize = [rep size];
if (repSize.width == 0 || repSize.height == 0) if (repSize.width <= 0 || repSize.height <= 0)
return nil; repSize = imageSize;
pixelsWide = [rep pixelsWide]; pixelsWide = [rep pixelsWide];
pixelsHigh = [rep pixelsHigh]; pixelsHigh = [rep pixelsHigh];
@ -2075,6 +2076,18 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
pixelsWide = repSize.width; pixelsWide = repSize.width;
pixelsHigh = repSize.height; pixelsHigh = repSize.height;
} }
}
else // e.g. when there are no representations at all
{
repSize = imageSize;
// FIXME: assumes 72 DPI. Also truncates, not sure if that is a problem.
pixelsWide = imageSize.width;
pixelsHigh = imageSize.height;
}
if (repSize.width <= 0 || repSize.height <= 0 ||
pixelsWide <= 0 || pixelsHigh <= 0)
return nil;
// Create a new cached image rep without any contents. // Create a new cached image rep without any contents.
cacheRep = [[cachedClass alloc] cacheRep = [[cachedClass alloc]
@ -2086,7 +2099,7 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
alpha: [rep hasAlpha]]; alpha: [rep hasAlpha]];
repd = [GSRepData new]; repd = [GSRepData new];
repd->rep = cacheRep; repd->rep = cacheRep;
repd->original = rep; repd->original = rep; // may be nil!
[_reps addObject: repd]; [_reps addObject: repd];
RELEASE(repd); /* Retained in _reps array. */ RELEASE(repd); /* Retained in _reps array. */