react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Crash with multi RootView by multi touch

Open littlesome opened this issue 10 years ago • 3 comments

I have many RCTRootView in my app, and got crash like this: (my app based on 0.30.0 iOS, this repro below uses 0.25.1)

2016-08-21 18:19:36.476 [info][tid:main][RCTPerformanceLogger.m:75] Unbalanced calls start/end for tag 15
2016-08-21 18:19:36.477 [info][tid:main][RCTPerformanceLogger.m:75] Unbalanced calls start/end for tag 15
2016-08-21 18:19:36.482 [info][tid:main][RCTPerformanceLogger.m:75] Unbalanced calls start/end for tag 15
2016-08-21 18:19:39.205 UIExplorer[6490:3038384] sendEvent topTouchStart, 1
2016-08-21 18:19:39.206 UIExplorer[6490:3038384] sendEvent topTouchStart, 1
2016-08-21 18:19:39.206 UIExplorer[6490:3038384] *** Assertion failure in -[RCTEventDispatcher sendEvent:](), /Users/lituo/Documents/rn/react-native/React/Base/RCTEventDispatcher.m:145
2016-08-21 18:19:39.212 UIExplorer[6490:3038384] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Got event <RCTTouchEvent: 0x12f8e5340; name = topTouchStart; coalescing key = 1> which cannot be coalesced, but has the same eventID 343532959170560 as the previous event <RCTTouchEvent: 0x12f8e4c30; name = topTouchStart; coalescing key = 1>'
*** First throw call stack:
(0x180a42db0 0x1800a7f80 0x180a42c80 0x1813c81c0 0x1001642ac 0x10012c0fc 0x10012c250 0x186131f30 0x185d46728 0x185bd37a0 0x186133530 0x185b924d8 0x185b8f254 0x185bd1610 0x185bd0c0c 0x185ba104c 0x185b9f628 0x1809f909c 0x1809f8b30 0x1809f6830 0x180920c50 0x182208088 0x185c0a088 0x1000a8bc8 0x1804be8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException`

UIExplorer's RCTRootView example can reproduces this bug (100%), try to touch the 'Embedded React Native view' and 'React Native Button' at the same time.

I noticed that in RCTEventDispatcher.m RCTGetEventID returns same value

static NSNumber *RCTGetEventID(id<RCTEvent> event)
{
  return @(
    event.viewTag.intValue |
    (((uint64_t)event.eventName.hash & 0xFFFF) << 32) |
    (((uint64_t)event.coalescingKey) << 48)
  );
}

for RCTTouchEvent viewTag: is always 0 coalescingKey: each RCTRootView's RCTTouchHandler has this value starting from 0

So set a viewTag (maybe just the target view's reactTag) for RCTTouchEvent solves this, any other better solutions?


And one more thing, I got warning 'Cannot find single active touch.' on JS side, stack:

reactConsoleError   @   ExceptionsManager.js:76
console.error   @   YellowBox.js:59
warning @   warning.js:44
recordTouchTrack    @   ResponderTouchHistoryStore.js:174
extractEvents   @   ResponderEventPlugin.js:441
extractEvents   @   EventPluginHub.js:186
handleTopLevel  @   ReactEventEmitterMixin.js:28
(anonymous function)    @   ReactNativeEventEmitter.js:125
perform @   Transaction.js:138
batchedUpdates  @   ReactDefaultBatchingStrategy.js:63
batchedUpdates  @   ReactUpdates.js:98
_receiveRootNodeIDEvent @   ReactNativeEventEmitter.js:124
receiveTouches  @   ReactNativeEventEmitter.js:186
__callFunction  @   MessageQueue.js:193
(anonymous function)    @   MessageQueue.js:94
guard   @   MessageQueue.js:41
callFunctionReturnFlushedQueue  @   MessageQueue.js:93
onmessage   @   debuggerWorker.js:39

UIExplorer's RCTRootView example can reproduces this bug (not 100% easier on real device), try to hold the 'Embedded React Native view' and then tap the 'React Native Button'.

There's already an issue for this #79, reopen it?

littlesome avatar Aug 21 '16 11:08 littlesome

For the first issue, after look into android's impl, I'm sure it's a bug. Android TouchEvent iOS RCTTouchEvent viewTag is missing

Touch event's coalesce logic is different on android and iOS, android's TouchEvent to native MotionEvent is 1: 1 for coalescing, while iOS's RCTTouchEvent to native UITouch is 1: N, which means 1 RCTTouchEvent may have many view's reactTags, and they all belongs to one same RCTRootView,

I think the easiest way to fix this is pass RCTRootView's tag as RCTTouchEvent's viewTag property, and I checked this works.

If this way is ok, I will send a PR.

littlesome avatar Aug 22 '16 02:08 littlesome

For the second issue: 'Cannot find single active touch', turnning off the RCTTouchHandler for the inner view solves this warning.

littlesome avatar Aug 31 '16 18:08 littlesome

@littlesome It happened to me, too. Did you send a PR?

rainer-liao avatar Sep 08 '16 10:09 rainer-liao