Whenever my method sets an object to onTouchEventReceiver, it gets lost when another method is called by another thread.
//In header
id onTouchEventReceiver;
SEL onTouchSelector;
- (void) setOnTouchSelector:(SEL)sel withObject:(id)obj
{
NSLog(@"setting obj to %@",obj);
onTouchSelector = sel;
[self setOnTouchEventReceiver:obj];
NSLog(@"====----- %@",onTouchEventReceiver); //That works
}
//Another thread calls this
- (void) touchEventReceived
{
NSLog(@"firing a selector at %@ by %@",onTouchEventReceiver,self);
//Why on earth does that happen?????
if (onTouchEventReceiver != nil) //onTouchEventReceiver is (null)
{
[onTouchEventReceiver performSelector:onTouchSelector];
}
}
The code produces the following:
2010-07-18 23:40:54.776 app[737:903] setting obj to <appCtl: 0x10fa00>
2010-07-18 23:40:54.787 app[737:903] ====----- <appCtl: 0x10fa00>
... after the screen was touched ...
Got touch event at coordinates 154 x 243 , mask : 2
2010-07-18 23:41:39.342 app[737:3b03] AALayer hit test passed : <AALayer: 0x110af0>
2010-07-18 23:41:39.348 app[737:3b03] firing a selector at (null) by <AALayer: 0x110af0>
Why does that happen? The code seems to be correct .