【发布时间】:2010-06-17 17:06:14
【问题描述】:
我正在尝试使用 Apple 编程指南中的 sn-p 代码,并且在执行 malloc 之后尝试将指针传递给函数时得到 EXC_BAD_ACCESS。
(供参考:iPhone Application Programming Guide: Event Handling - Listing 3-6)
有问题的代码很简单:
CFMutableDictionaryRef touchBeginPoints;
UITouch *touch;
....
CGPoint *point = (CGPoint *)CFDictionaryGetValue(touchBeginPoints, touch);
if (point == NULL)
{
point = (CGPoint *)malloc(sizeof(CGPoint));
CFDictionarySetValue(touchBeginPoints, touch, point);
}
现在,当程序进入if 语句时,它会将malloc 的“输出”分配给point 变量/指针。
然后,当它尝试将point 传递给CFDictionarySetValue 函数时,它会导致应用程序崩溃:Program received signal: “EXC_BAD_ACCESS”.
有人建议不要使用malloc 并将point 变量/指针传递为:&point,但这仍然给了我EXC_BAD_ACCESS。
我(看起来像苹果)做错了什么???
提前致谢。
【问题讨论】:
标签: iphone c uikit core-foundation