DNESS / cocos2d-iphone

Automatically exported from code.google.com/p/cocos2d-iphone
1 stars 0 forks source link

TouchDispatcher - problem with add/remove locking #1084

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
When some object gets a touch event:
Create a new layer.
Set its isTouchEnabled to YES.
Set its isTouchEnabled to NO.
Remove the layer.

What is the expected output? What do you see instead?
Possible crash when you next get touch events.

What cocos2d version are you using ?
0.99.5

What iOS / Mac SDK are you using ?
4.2

Debug or Release ?
Both.

iOS only: Does this happens on device ? or on the simulator ? or on both ?
Both.

Please provide any additional information below.

I've got a little bit hacky way to do modal GUI dialogs to not to have roll too 
much of my own code. Every dialog has a CCMenu, when a modal dialog is pushed 
on top of another, it does isTouchEnabled -> NO and the new top window enables 
it. The problem was starting to happen when a modal window was sending a 
message to the window under it then removed itself, and the window then removed 
itself also. This is all happening in the same touch event, so the window gets 
the "touchEnabled" because it's now on top, but then removes it self sending 
the "touchDisable".

Since this is happening during the touch dispatch loop, adding and removing is 
deferred. When the loop finishes the elements are first REMOVED and then ADDED. 
That means I get an object that was just destroyed left in the TouchDispatcher.

My current (non)solution is to fist have adding than removing, in the 
CCTouchDispatcher.m in method:
-(void) touches:(NSSet*)touches withEvent:(UIEvent*)event 
withTouchType:(unsigned int)idx;

Original issue reported on code.google.com by podhrask...@gmail.com on 8 Jan 2011 at 2:20

GoogleCodeExporter commented 9 years ago

Original comment by ricardoq...@gmail.com on 13 Jan 2011 at 7:18

GoogleCodeExporter commented 9 years ago
Your solution works great also for #1139. I believe both issues are similar. 
Thank you for your contribution.

Original comment by a1rex2...@gmail.com on 4 Jun 2011 at 12:28

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, fixed.

https://github.com/cocos2d/cocos2d-iphone/commit/d1e31283e1ada3244926c0bfb70d671
f46a0bd86

Original comment by marcotil...@gmail.com on 25 Oct 2011 at 9:54