简体   繁体   English

内存中存在对象时代码为2的EXC_BAD_ACCESS

[英]EXC_BAD_ACCESS with Code=2 While Objects Exist In Memory

Can anybody kindly take his time and explain how it is possible to get such EXC_BAD_ACCESS exception while parentVC & parentVC.audioHandler & parentVC.audioHandler.player all do exist in memory ? 任何人都可以请他花点时间解释一下EXC_BAD_ACCESS异常,而parentVCparentVC.audioHandlerparentVC.audioHandler.player都存在于内存中吗? ( they all are created with a strong pointer to them ) (它们都是用指向它们的strong指针创建的)

在此处输入图片说明

PS: player is an AVAudioPlayer and obviously has an isPlaying method. PS: playerAVAudioPlayer ,显然具有isPlaying方法。

PPS: player is as same as parentVC.audioHandler.player and is defined a few lines higher as : PPS: playerparentVC.audioHandler.player相同,并且定义为:

AVAudioPlayer *player = parentVC.audioHandler.player;

Found the problem : 发现问题:

player is a valid AVAudioPlayer object and correctly exists in the memory. player是有效的AVAudioPlayer对象,并且正确存在于内存中。

The problem is that it is allocated with init method like : 问题在于它是通过init方法分配的,例如:

self.player = [[AVAudioPlayer alloc] init];

Which is wrong because AVAudioPlayer doesn't have an init method, you should use initWithURL or initWithData instead ! 这是错误的,因为AVAudioPlayer没有init方法,您应该改用initWithURLinitWithData

Hope this can help somebody else. 希望这可以帮助其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM