我正在使用 cocos3D(但这没关系..)
@interface MyScene : CC3Scene
{
MyObject *theObject;
GameLogic *gLogic;
}
@implementation MyScene
-(void)initializeScene
{
gLogic = [[[GameLogic alloc] init] autorelease];
theObject = [[[MyObject alloc] init] autorelease];
[self addChild:theObject];
[[NSNotificationCenter defaultCenter] addObserver:gLogic
selector:@selector(testHandler:)
name:@"objectMoved"
object:theObject];
}
在 GameLogic 中,我有一个简单的通知处理程序(也在标题中声明)...
-(void)testHandler:(NSNotification*)notification
{
NSLog(@"Notification: %@", [notification name]);
}
在 MyObject 中,到了时候,我调用这个方法
-(void)dispatchEvent
{
NSLog(@"SHOULD DISPATCH THE EVENT");
[[NSNotificationCenter defaultCenter] postNotificationName:@"objectMoved" object:self];
NSLog(@"EVENT DISPATCHED");
}
但它崩溃突出显示 postNotificationName 行......错误是 EXC_BAD_ACCESS 意思(如果我理解正确)有一些对已释放对象的引用......
发生了什么?