discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImage / NSImageRep copy bug/problem


From: Riccardo Mottola
Subject: NSImage / NSImageRep copy bug/problem
Date: Sun, 30 Nov 2014 15:27:38 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:33.0) Gecko/20100101 Firefox/33.0 SeaMonkey/2.30

Hi,

I have updated PRICE's (http://sourceforge.net/projects/price/) PRImage to keep a reference to my local image representation.

Here you can see the source code:
http://price.cvs.sourceforge.net/viewvc/price/PRICE-osx/PRImage.m?view=markup

In initWithData I simply do:
  self = [super initWithData:data];
  bitRep = [[self representations] objectAtIndex:0];
  [bitRep retain];

My copyWithZone implementation is as following>
- (id)copyWithZone:(NSZone *)zone
{
  PRImage *objCopy;

  objCopy = [super copyWithZone:zone];
  while( [[objCopy representations] count] > 0 )
    {
[objCopy removeRepresentation:[[objCopy representations] objectAtIndex:0]];
    }
  objCopy->bitRep = nil;
  [objCopy setBitmapRep:[[bitRep copy] autorelease]];

  return objCopy;
}

I suppose it is a fine idea to invalidate all representations and then re-adding a copy of the principal one.

Copying is used during Undo, when the old image gets saved o during Redo.

This work fine on OS-X. I tried both 10.4 (ppc) and 10.6 (intel). However on GNUstep I get a crash (see below).
The crash happens when the old image gets released.

Undo has 1 level, I just have a copy of the old image. I release it before putting the next one in.

Why does it crash?
I have two guesses:
1) NSBitmapImageRep's copyWithZone doens't work correctly or as on Mac
2) NSImage copy is different/buggy? I do a superCopyWithZone
3) GS retains/releases its representations differently.

It could also be a problem in PRICE's code, perhaps in the copy code and that it works "by chance" on the mac

Riccardo

#0  0xb76872f3 in objc_msg_lookup ()
   from /usr/lib/gcc/i686-pc-linux-gnu/4.8.3/libobjc.so.4
#1  0xb7c33f7c in -[NSBitmapImageRep dealloc] (self=0x8231a88,
    _cmd=0xb7af1dd0 <_OBJC_SELECTOR_TABLE+304>) at NSBitmapImageRep.m:622
#2  0xb785382c in -[NSObject release] (self=0x8231a88,
    _cmd=0xb7f28050 <_OBJC_SELECTOR_TABLE+912>) at NSObject.m:2102
#3  0xb7cb7738 in -[GSRepData dealloc] (self=0x822ec28,
    _cmd=0xb7af1dd0 <_OBJC_SELECTOR_TABLE+304>) at NSImage.m:117
#4  0xb785382c in -[NSObject release] (self=0x822ec28,
    _cmd=0xb7aa5ca0 <_OBJC_SELECTOR_TABLE+96>) at NSObject.m:2102
#5  0xb7728aa3 in -[GSArray dealloc] (self=0x81815a8,
    _cmd=0xb7af1dd0 <_OBJC_SELECTOR_TABLE+304>) at GSArray.m:137
#6  0xb785382c in -[NSObject release] (self=0x81815a8,
    _cmd=0xb7f28050 <_OBJC_SELECTOR_TABLE+912>) at NSObject.m:2102
#7  0xb7cb7966 in -[NSImage dealloc] (self=0x8311268,
    _cmd=0x8099460 <_OBJC_SELECTOR_TABLE+960>) at NSImage.m:417
#8  0x0806678e in -[PRImage dealloc] (self=0x8311268,
    _cmd=0xb7af1dd0 <_OBJC_SELECTOR_TABLE+304>) at PRImage.m:60
#9  0xb785382c in -[NSObject release] (self=0x8311268,
    _cmd=0x8079d08 <_OBJC_SELECTOR_TABLE+1032>) at NSObject.m:2102
#10 0x0804ba43 in -[MyDocument saveCurrentImage] (self=0x839e330,
    _cmd=0x8079db8 <_OBJC_SELECTOR_TABLE+1208>) at MyDocument.m:366
#11 0x0804cd9d in -[MyDocument runFilter:with:] (self=0x839e330,
    _cmd=0x809d2f8 <_OBJC_SELECTOR_TABLE+856>, filter=0x84591a8,
    parameters=0x0) at MyDocument.m:300




reply via email to

[Prev in Thread] Current Thread [Next in Thread]