Re: Passing C Style Function Callbacks in Cocoa
Re: Passing C Style Function Callbacks in Cocoa
- Subject: Re: Passing C Style Function Callbacks in Cocoa
- From: Fritz Anderson <email@hidden>
- Date: Wed, 7 Apr 2004 10:15:50 -0500
EXC_BAD_ACCESS in objc_msgSend smells like an attempt to use an object
after it had been released. Audit your releases and autoreleases. Add a
test for nil in your init method for myObject13, and handle the error,
rather than silently aliasing and leaking if you have an overrun bug.
Have a look at <Foundation/NSDebug.h>, and set NSZombieEnabled=YES (for
debug purposes only) in your main() function, for help in tracking
overreleased objects.
-- F
On 6 Apr 2004, at 8:28 PM, Vince Ackerman wrote:
Well, I thought I had solved my problem with passing C style function
callbacks and then being able to find the appropriate object/method. I
am using the technique suggest by Hiro Fujimoto:
static id myObject10 // Declared in top of each object's .m file
outside the objects methods
static id myObject11 // etc
// As each IODinObj device object is initialized, I assign one of the
static myObjectX's to it
- (id) init
{
self = [super init];
// Check if another IODin Device was created and is using myObject(x)
// If not, assign it to this IODinObj
if (myObject10 == nil)
myObject10 = self;
else if (myObject11 == nil)
myObject11 = self;
else if (myObject12 == nil)
myObject12 = self;
else
myObject13 = self;
return self;
}
// This is the callback passed to the USB device:
TeleoError IODinValueCB( TMioDin* tmdin, bool aValue)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // fixes
memory leak for some reason
// Find out which IODinObj is making the callback
if ( [myObject10 IODinDevice] == tmdin)
[myObject10 updateValue: aValue];
else if ( [myObject11 IODinDevice] == tmdin)
[myObject11 updateValue: aValue];
else if ( [myObject12 IODinDevice] == tmdin)
[myObject12 updateValue: aValue];
else
[myObject13 updateValue: aValue];
[pool release];
return TELEO_OK;
}
I have about 10 of the exact same callback functions throughout my code
and most work without error, however this one which used to work now
crashes every time it's called. Don't know what changed, but maybe it
was only luck that made it work to begin with. Can anyone suggest what
I'm doing wrong?
Stack trace:
#0 0x908311ec in objc_msgSend // <--- Disassembles here (below)
#1 0x004d56a0 in IODinValueCB at IODinObj.m:37 // <----- this is my C
style callback that was passed earlier to the USB Device
#2 0x01748df8 in TMioDin_propertyUpdate at TeleoMioDin.c:332 // <----
this is third party USB device code
0x908311e0 <+0000> cmplwi r3,0
0x908311e4 <+0004> beq- 0x90831308 <objc_msgSend+296>
0x908311e8 <+0008> lwz r12,0(r3)
0x908311ec <+0012> lwz r12,32(r12) <----------Crashes here with:
"Program received signal: "EXC_BAD_ACCESS". "
0x908311f0 <+0016> stw r9,48(r1)
0x908311f4 <+0020> lwz r11,0(r12)
0x908311f8 <+0024> addi r9,r12,8
0x908311fc <+0028> rlwinm r11,r11,2,0,29
0x90831200 <+0032> and r12,r4,r11
0x90831204 <+0036> lwzx r2,r9,r12
0x90831208 <+0040> addi r12,r12,4
0x9083120c <+0044> cmplwi r2,0
0x90831210 <+0048> beq- 0x90831234 <objc_msgSend+84>
Thanks in advance
Vince
_______________________________________________
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.