"Delegate already added to touch dispatcher."的解决方案
2012-05-17 10:27
483 查看
错误提示:
*** Assertion failure in -[CCTouchDispatcher forceAddHandler:array:]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate already added to touch dispatcher.'
分析:
在触摸屏幕时,会调用下面的伪代码,其中idx是一种枚举类型,表示Touchbegin、TouchEnd等等
比如你在ccTouchesBegan:withEvent: 中调用[self setIsTouchEnabled:NO]或者[self setIsTouchEnabled:YES];
由于正在触摸,locked = YES;
因此需要添加的handler和需要移除的的handler分别存储在两个不同的可变数组中,并非马上添加或者删除。
这两个CCTouchDispatcher中的数组分别是NSMutableArray*handlersToAdd; NSMutableArray*handlersToRemove;
当消息分发完毕后,会从上述伪代码的第6行开始继续执行,可以看出,会先删除handlersToRemove数组中的元素,后增加handlersToAdd中的元素。
正因为如此,如果你在同一次ccTouchesBegan中先调用[self setIsTouchEnabled:YES],再调用[self setIsTouchEnabled:NO],你本以为这与“只调用[self setIsTouchEnabled:NO]”一样,其实不然。执行完后也许还是[self setIsTouchEnabled:YES];的效果,这和isTouchEnabled_又有关系,具体问题具体分析了。
强烈建议参看:全面剖析Cocos2d游戏触摸机制,看完自然都熟悉了。
*** Assertion failure in -[CCTouchDispatcher forceAddHandler:array:]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate already added to touch dispatcher.'
分析:
在触摸屏幕时,会调用下面的伪代码,其中idx是一种枚举类型,表示Touchbegin、TouchEnd等等
1 -(void) touches:(NSSet*)touches withEvent:(UIEvent*)event withTouchType:(unsigned int)idx{ 2 locked = YES; 3 触摸消息的转发... 4 locked = NO; 5 // 先删除代理对象,再增加代理对象 6 if(ToRemove){ 7 remove from NeedToRemoved 8 } 9 if(ToAdd){ 10 add from NeedToAdd 11 } 12 }
比如你在ccTouchesBegan:withEvent: 中调用[self setIsTouchEnabled:NO]或者[self setIsTouchEnabled:YES];
由于正在触摸,locked = YES;
因此需要添加的handler和需要移除的的handler分别存储在两个不同的可变数组中,并非马上添加或者删除。
这两个CCTouchDispatcher中的数组分别是NSMutableArray*handlersToAdd; NSMutableArray*handlersToRemove;
当消息分发完毕后,会从上述伪代码的第6行开始继续执行,可以看出,会先删除handlersToRemove数组中的元素,后增加handlersToAdd中的元素。
1 - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 2 [self setIsTouchEnabled:YES]; 3 [self setIsTouchEnabled:NO]; 4 }
正因为如此,如果你在同一次ccTouchesBegan中先调用[self setIsTouchEnabled:YES],再调用[self setIsTouchEnabled:NO],你本以为这与“只调用[self setIsTouchEnabled:NO]”一样,其实不然。执行完后也许还是[self setIsTouchEnabled:YES];的效果,这和isTouchEnabled_又有关系,具体问题具体分析了。
强烈建议参看:全面剖析Cocos2d游戏触摸机制,看完自然都熟悉了。
相关文章推荐
- <常见错误>"Delegate already added to touch dispatcher."的解决方案
- Ubuntu升级到16.04后出现"Failed to start Load Kernel Modules"问题的解决方案
- asp.net在发送邮件时出现"服务器响应为: You are not authorized to send mail, authentication is required "解决方案
- "Error, some other host already uses address"的解决方案
- "fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt"解决方案
- silverlight无法调试"unable to start program 数据无效" 解决方案
- 安装完android studio,启动时碰到"failed to load jvm dll"的解决方案
- 关于"Cannot change version of project facet Dynamic web module to 3.0"问题的简单解决方案(备忘)
- 安装VS2003时,"Setup Has Detected That Another Program Requires the Computer to Reboot"问题的解决方案
- IDA Pro调试出现"Could not connect to localhost: 由于目标计算机积极拒绝,无法连接。"的解决方案
- Ubuntu"无法连接到 Upstart: Failed to connect to socket /com/ubuntu/upstart: 拒绝连接"的解决方案
- "由于这台计算机没有远程桌面客户端访问许可证,远程会话被中断"的解决方案
- 升级sp3后出现"一个问题阻止windows正确检测此机器许可证"解决方案
- MSSQL数据库 "无法删除数据库 "***",因为该数据库当前正在使用" 解决方案
- "ConfigurationSettings已过时"全面解决方案
- 打开Eclipse时出现"Failed to create the Java Virtual Machine"怎么办?
- 执行git push出现"Everything up-to-date"
- "malloc: * error for object 0x17415d0c0: Invalid pointer dequeued from free list * set a breakpoint in malloc_error_break to debug";
- 执行git push出现"Everything up-to-date"
- "XX cannot be resolved to a type "eclipse报错(工程图标出现红叉符号)及解决说明