NSTableView custom subclass causes random crashes if declared in IB
NSTableView custom subclass causes random crashes if declared in IB
- Subject: NSTableView custom subclass causes random crashes if declared in IB
- From: Shaun Wexler <email@hidden>
- Date: Sat, 11 Jan 2003 06:57:33 -0800
Help please!
I wrote a subclass of NSTableView to replace the default dragging image
in the method (dragImageForRows:event:dragImageOffset:).
This works perfectly, when the class gets loaded, but I'm having random
crashes within AppKit and Foundation when it's used on objects assigned
with it as a custom class in IB. I was having the same type of
problems with a subclass of NSPopUpButton, until I implemented
(initWithCoder:) which just returns [self = [super
initWithCoder:coder], but that doesn't fix my NSTableView subclass.
These subclasses are both in my main bundle's target, and each class
only overrides a single superclass method. Other dynamic bundles use
these classes from the main bundle, but do not include these subclasses
class in their own targets, and none of my code points to the custom
classes directly, but rather their superclasses. Each time a new
window is requested from one of these bundles, it loads its nib with
the window and/or view. The nibs do not contain instances of the
controller classes; all use File's Owner for outlets and actions.
There are two of my custom-classed NSTableViews within a panel in the
nib.
In IB, reverting the objects using custom classes eliminates any
crashes in the app & bundles.
Crashes are noted internally, private within NSWindow(NSDrag),
NSView(NSDrag) and various Cell classes which are apparently being
autoreleased after dealloc, over which I have no control, since it's
all happening within or in methods immediately afteror containing the
NSBundle calls using NSNibLoading.
I tried implementing these methods as categories, since they don't need
instance variables, but without the ability to call super, it's too
much work to replicate super's behavior in the category methods.
Not sure if this is a Cocoa or IB problem. Does it have something to
do with how I've subclassed it? Can anyone give me some ideas?
Thanks! The method is shown below. Super's NSImage and my custom
image are both autoreleased, and each have a retain count of 1 upon
exit of this method.
--
Shaun Wexler,
http://www.hellsgate-sound.com
http://www.macfoh.com
http://www.aapls.com
============================================
- (NSImage *) dragImageForRows:(NSArray *)rows event:(NSEvent *)event
dragImageOffset:(NSPointPointer)offset
{
// get NSTableView's default drag image
NSImage *defaultImage = [super dragImageForRows:rows event:event
dragImageOffset:offset];
// draw into a new larger image
NSSize frameSize = NSMakeSize([defaultImage size].width + 3.0f,
[defaultImage size].height + 2.0f);
NSImage *newImage = [[[NSImage alloc] initWithSize:frameSize]
autorelease];
[newImage lockFocus];
// add a soft-edged blue fill to the default NSTableView's drag image
[[[NSColor alternateSelectedControlColor]
colorWithAlphaComponent:0.30f] set];
NSRectFill(NSMakeRect(0.0f, 0.0f, frameSize.width, frameSize.height));
[[[NSColor alternateSelectedControlColor]
colorWithAlphaComponent:0.15f] set];
NSFrameRect(NSMakeRect(0.0f, 0.0f, frameSize.width, frameSize.height));
// draw the default image under the translucent layer
[defaultImage compositeToPoint:NSMakePoint(1.0f, 1.0f)
operation:NSCompositeDestinationOver];
// end drawing
[newImage unlockFocus];
return newImage;
}
============================================
Crash Reporter Log:
Date/Time: 2003-01-11 06:27:05 -0800
OS Version: 10.2.3 (Build 6G30)
Host: xxx
Command: MacFOH
PID: 7476
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000
Thread 0 Crashed:
#0 0x9068ba54 in objc_msgSend
#1 0x907e2e14 in -[NSArray makeObjectsPerformSelector:withObject:]
#2 0x930b7808 in -[NSView _windowChangedKeyState]
#3 0x907e2e14 in -[NSArray makeObjectsPerformSelector:withObject:]
#4 0x930b7808 in -[NSView _windowChangedKeyState]
#5 0x907e2e14 in -[NSArray makeObjectsPerformSelector:withObject:]
#6 0x930b7808 in -[NSView _windowChangedKeyState]
#7 0x907e2e14 in -[NSArray makeObjectsPerformSelector:withObject:]
#8 0x930b7808 in -[NSView _windowChangedKeyState]
#9 0x9313e780 in -[NSFrameView _windowChangedKeyState]
#10 0x9316842c in -[NSWindow _setFrameNeedsDisplay:]
#11 0x93167f04 in -[NSWindow makeKeyAndOrderFront:]
#12 0x026910e4 in -[AnalyzerController newWindow]
#13 0x02690a80 in +[AnalyzerController newAnalyzerWindow]
#14 0x026894f4 in -[AnalyzerManager performActionForMenuItem:]
#15 0x000081a0 in -[AppDelegate doAnalyzer:] (AppDelegate.m:880)
#16 0x930f90e4 in -[NSApplication sendAction:to:from:]
#17 0x9316e664 in -[NSMenu performActionForItemAtIndex:]
#18 0x931aed58 in -[NSCarbonMenuImpl
performActionWithHighlightingForItemAtIndex:]
#19 0x930ebb54 in _NSHandleCarbonMenuEvent
#20 0x9308dbfc in _DPSNextEvent
#21 0x9309fb04 in -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:]
#22 0x930b15e4 in -[NSApplication run]
#23 0x9315f6b8 in NSApplicationMain
#24 0x00003c28 in main (MacFOH.m:21)
#25 0x000039ac in _start (crt.c:267)
#26 0x0000382c in start
Thread 1:
#0 0x90073c48 in mach_msg_trap
#1 0x90005f90 in mach_msg
#2 0x90148b10 in __CFRunLoopRun
#3 0x90180fe4 in CFRunLoopRunSpecific
#4 0x94d9c1c0 in HALRunLoop::OwnThread(void*)
#5 0x94d911b0 in CAPThread::Entry(CAPThread*)
#6 0x90020d48 in _pthread_body
Thread 2:
#0 0x9003eaa8 in semaphore_wait_signal_trap
#1 0x9003e8c4 in _pthread_cond_wait
#2 0x90824180 in -[NSConditionLock lockWhenCondition:]
#3 0x93081388 in -[NSUIHeartBeat _heartBeatThread:]
#4 0x9081cd38 in forkThreadForFunction
#5 0x90020d48 in _pthread_body
PPC Thread State:
srr0: 0x9068ba54 srr1: 0x0000f030 vrsave: 0x00000000
xer: 0x00000000 lr: 0x907e2e14 ctr: 0x9068ba3c mq: 0x00000000
r0: 0x907e2e14 r1: 0xbfffe210 r2: 0x24044282 r3: 0x00141430
r4: 0x906a3f1c r5: 0x00000000 r6: 0x00141430 r7: 0x00000001
r8: 0x00000000 r9: 0xbfffe250 r10: 0x0012fbb0 r11: 0xa07e0c90
r12: 0x00000000 r13: 0x00000000 r14: 0x00000000 r15: 0x00000000
r16: 0x00000000 r17: 0xbffff640 r18: 0x00000000 r19: 0xffffffff
r20: 0x0014b8f0 r21: 0xa309d744 r22: 0xbffff7a0 r23: 0x00225e70
r24: 0x00000000 r25: 0x906a3f1c r26: 0x026cb450 r27: 0x00000001
r28: 0x00000000 r29: 0x00000001 r30: 0x00000001 r31: 0x907e2d14
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.