Re: A CFStringRef that throws EXC_BAD_ACCESS
Re: A CFStringRef that throws EXC_BAD_ACCESS
- Subject: Re: A CFStringRef that throws EXC_BAD_ACCESS
- From: Craig Bakalian <email@hidden>
- Date: Thu, 17 Oct 2002 06:48:44 -0400
Hi Rosyna,
The story kinda goes like this... I am making a Midi Sequencer, so I
need to access the usb port and get the midi keyboards, drum machines,
tones generators, on and on. So, the application needs to know what
these devices can and cannot do. Amongst many other calls, this
particular call kept giving me and error
CFStringRef pmaxtrans;
MIDIDeviceRef dev;
MIDIObjectGetStringProperty(dev, kMIDIPropertyMaxTransmitChannels,
&pmaxtrans); put ref in pmaxtrans
CFStringGetCString(pmaxtrans, cmaxtrans, sizeof(pmaxtrans), 0); //set
the stringRef to a string
[self setMaxTransChannels: [NSString stringWithCString: cmaxtrans]];
//put string in NSString
The CFStringGetCString threw the bad access error because I was not
checking the return value of the MIDIObjectGetStringProperty(blah,
blah,blah). So, I did this
CFStringRef pmaxtrans;
MIDIDeviceRef dev;
OSStatus TransErr = MIDIObjectGetStringProperty(dev,
kMIDIPropertyMaxTransmitChannels, &pmaxtrans);
if(TransErr != kMIDIUnknownProperty ){
CFStringGetCString(pmaxtrans, cmaxtrans, sizeof(pmaxtrans), 0);
CFRelease(pmaxtrans);
[self setMaxTransChannels: [NSString stringWithCString:
cmaxtrans]];
}
The only thing different about the two versions is the second one
checks the OSStatus!
But, why did the compiler let me do the first one without telling me it
needed a return value?
Craig Bakalian
On Wednesday, October 16, 2002, at 08:54 PM, Rosyna wrote:
>
I didn't quite understand your question or solution. How were you
>
making the CFStringRef?
>
>
Ack, at 10/16/02, Craig Bakalian said:
>
>
> I got my answer after fussing with CFStringRef for about one hour.
>
> God, I hate moments like those.
>
> It just happens that the function that made &myCFString needed an
>
> OSStatus err set with a value returned
>
> indicating EXC_BAD_ACCESS. I miss java and exception handling. Why
>
> did the compiler let me call a
>
> function without a return value when it needed it? Whatever... just
>
> point to a bad address.
>
>
>
> Craig Bakalian
>
>
--
>
>
>
Sincerely,
>
Rosyna Keller
>
Technical Support/Holy Knight/Always needs a hug
>
>
Unsanity: Unsane Tools for Insanely Great People
>
---
>
>
Please include any previous correspondence in replies, it helps me
>
remember what we were talking about. Thanks.
_______________________________________________
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.