EXC_BAD_ACCESS in dragImage:
EXC_BAD_ACCESS in dragImage:
- Subject: EXC_BAD_ACCESS in dragImage:
- From: Nat! <email@hidden>
- Date: Thu, 1 Nov 2001 13:58:34 +0100
I get this EXC_BAD_ACCESS error often, when I am dragging an image
outside of the window it originated from. It will never happen when
the drag stays in the window.
Fascinatingly, while I am crashed in the debugger, at that point
the Dock will not respond to events anymore until I quit the
debugger.
I can't quite imagine that dragging is that hosed so maybe
something is wrong with my code ? (For that reason I did not yet
write my daily bug report)
Nat!
That's the code of my NSView subclass, it is called from my NSCell
subclass trackMouse:inRect:ofView:untilMouseUp: method
- (BOOL) mulleStartDraggingForEvent:(NSEvent *) event
{
NSPasteboard *pasteboard;
NSImage *image;
NSSize size;
NSPoint point;
NSData *data;
image = [self selectedImage]; // some NSImage...
data = [image TIFFRepresentation];
if( ! [data length])
return( NO);
pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pasteboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]
owner:nil];
if( ! [pasteboard set
Data:data
forType:NSTIFFPboardType])
{
NSLog( @"%@ failed to accept TIFF data of %u bytes",
pasteboard, [data length]);
return( YES); // tried our best
}
pasteboard = [NSPasteboard pasteboardWithName:NSGeneralPboard];
[pasteboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]
owner:nil];
if( ! [pasteboard set
Data:data
forType:NSTIFFPboardType])
{
// could also raise
NSLog( @"%@ failed to accept TIFF data of %u bytes",
pasteboard, [data length]);
return( YES); // tried our best
}
// this creates a "thumbnail" image for dragging
image = [self dragImageForImage:image
maxSize:NSMakeSize( 200, 150)];
size = [image size];
point = [event locationInWindow];
point.x -= size.width / 2;
point.y -= size.height / 2;
// I did notice that the retainCount of my data stays at 1,
// even if I put it on two pasteboards. Experimentally
// retaining it twice here didn't help any,
// It seems that the data is copied onto the pasteboard.
[[self window] dragImage:image
at:point
offset:NSZeroSize
event:event
pasteboard:pasteboard
source:self
slideBack:YES];
return( YES);
}
Here are two different stack traces
DebugAssert: Third Party Client: (Handle)theAEDesc->dataHandle !=
0 [line 162, file Source/AppleEventAccessors.cp]
Program received signal EXC_BAD_ACCESS, Could not access memory.
0x735f8768 in AEFlattenDesc ()
(gdb) where
#0 0x735f8768 in AEFlattenDesc ()
#1 0x73d76204 in BuildIPCPackage ()
#2 0x73d7f748 in SendDragIPCMessage ()
#3 0x73d7f990 in SendDropMessage ()
#4 0x73d7d378 in DragInApplication ()
#5 0x73d71834 in DragLoop ()
#6 0x73d7a344 in CoreDragStartDragging ()
#7 0x70cfbde0 in -[NSCoreDragManager _dragUntilMouseUp:accepted:] ()
#8 0x70cfc81c in -[NSCoreDragManager
dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:] ()
#9 0x70da3624 in -[NSWindow(NSDrag)
dragImage:at:offset:event:pasteboard:source:slideBack:] ()
#10 0x5010428c in -[MulleTIFFSelectingImageView
mulleStartDraggingForEvent:] (self=0x134df0, _cmd=0x501047c4,
event=0x0) at MulleTIFFSelectingImageView.m:193
#11 0x50102d78 in -[MulleScreeningImageCell
trackMouse:inRect:ofView:untilMouseUp:] (self=0x135110,
_cmd=0x706c028c, event=0x0, cellFrame={origin = {x = 0, y = 0},
size = {width = 1040, height = 1040}}, controlView=0x134df0,
untilMouseUp=0 '\000') at MulleScreeningImageCell.m:433
#12 0x70cfaef0 in -[NSControl mouseDown:] ()
#13 0x70c1b8f8 in -[NSWindow sendEvent:] ()
#14 0x70b9479c in -[NSApplication sendEvent:] ()
#15 0x70c23488 in -[NSApplication run] ()
#16 0x70c91ed0 in NSApplicationMain ()
#17 0x00002e14 in main (argc=1, argv=0xbffffd10) at main.m:4
#18 0x00002cb8 in _start ()
#19 0x00002ae8 in start ()
and
Program received signal EXC_BAD_INSTRUCTION, Illegal
instruction/operand.
0x00040000 in ?? ()
(gdb) where
#0 0x00040000 in ?? ()
#1 0x73d7f498 in SampleMouseAndKeyboard ()
#2 0x73d71834 in DragLoop ()
#3 0x73d7a344 in CoreDragStartDragging ()
#4 0x70cfbde0 in -[NSCoreDragManager _dragUntilMouseUp:accepted:] ()
#5 0x70cfc81c in -[NSCoreDragManager
dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:] ()
#6 0x70da3624 in -[NSWindow(NSDrag)
dragImage:at:offset:event:pasteboard:source:slideBack:] ()
#7 0x50104184 in -[MulleTIFFSelectingImageView
mulleStartDraggingForEvent:] (self=0x134df0, _cmd=0x50104704,
event=0x0) at MulleTIFFSelectingImageView.m:194
#8 0x50102c10 in -[MulleScreeningImageCell
trackMouse:inRect:ofView:untilMouseUp:] (self=0x135110,
_cmd=0x706c028c, event=0x0, cellFrame={origin = {x = 0, y = 0},
size = {width = 1040, height = 1040}}, controlView=0x134df0,
untilMouseUp=0 '\000') at MulleScreeningImageCell.m:433
#9 0x70cfaef0 in -[NSControl mouseDown:] ()
#10 0x70c1b8f8 in -[NSWindow sendEvent:] ()
#11 0x70b9479c in -[NSApplication sendEvent:] ()
#12 0x70c23488 in -[NSApplication run] ()
#13 0x70c91ed0 in NSApplicationMain ()
#14 0x00002e14 in main (argc=1, argv=0xbffffd10) at main.m:4
#15 0x00002cb8 in _start ()
------------------------------------------------------
Some people drink deep from the fountains of life, and
some just gargle. -- DLR