Malloc to a CGPoint Pointer throwing EXC_BAD_ACCESS when accessing
Posted
by kdbdallas
on Stack Overflow
See other posts from Stack Overflow
or by kdbdallas
Published on 2010-06-17T17:06:14Z
Indexed on
2010/06/17
17:23 UTC
Read the original article
Hit count: 339
I am trying to use a snippet of code from a Apple programming guide, and I am getting a EXC_BAD_ACCESS when trying to pass a pointer to a function, right after doing a malloc.
(For Reference: iPhone Application Programming Guide: Event Handling - Listing 3-6)
The code in question is really simple:
CFMutableDictionaryRef touchBeginPoints;
UITouch *touch;
....
CGPoint *point = (CGPoint *)CFDictionaryGetValue(touchBeginPoints, touch);
if (point == NULL)
{
point = (CGPoint *)malloc(sizeof(CGPoint));
CFDictionarySetValue(touchBeginPoints, touch, point);
}
Now when the program goes into the if
statement it assigns the 'output' of malloc
into the point
variable/pointer.
Then when it tries to pass point
into the CFDictionarySetValue
function it crashes the application with: Program received signal: “EXC_BAD_ACCESS”.
Someone suggested not doing the malloc
and pass the point
var/pointer as: &point
, however that still gave me a EXC_BAD_ACCESS
.
What I am (and it looks like Apple) doing wrong???
Thanks in advance.
© Stack Overflow or respective owner