Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] App crash when onCancel is fired a lot of times #142

Closed
zoontek opened this issue Mar 9, 2016 · 9 comments
Closed

[Android] App crash when onCancel is fired a lot of times #142

zoontek opened this issue Mar 9, 2016 · 9 comments

Comments

@zoontek
Copy link

zoontek commented Mar 9, 2016

Hello,

I might have a little problem with this code (at least, I think):

/**
 * override onCancel method to callback cancel in case of a touch
 * outside of the dialog or the BACK key pressed
 */
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialog) {
        dialog.dismiss();
        response.putBoolean("didCancel", true);
        callback.invoke(response);
    }
});

which could cause this error when I click at multiples times outside the popup:

03-09 17:08:12.354 2798-5915/com.mycompany.myapp E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
  Process: com.mycompany.myapp, PID: 2798
  com.facebook.react.bridge.ObjectAlreadyConsumedException: Receiving map already consumed
      at com.facebook.react.bridge.WritableNativeMap.putBoolean(Native Method)
      at com.imagepicker.ImagePickerModule$2.onCancel(ImagePickerModule.java:141)
      at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1326)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:148)
      at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:185)
      at java.lang.Thread.run(Thread.java:818)
03-09 17:08:12.481 2798-2798/com.mycompany.myapp I/TSLocationManager: - RNBackgroundGeolocationModule#destroy
03-09 17:08:12.526 2798-2809/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
      at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
      at android.os.Handler.enqueueMessage(Handler.java:631)
      at android.os.Handler.sendMessageAtTime(Handler.java:600)
      at android.os.Handler.sendMessageDelayed(Handler.java:570)
      at android.os.Handler.sendEmptyMessageDelayed(Handler.java:534)
      at android.os.Handler.sendEmptyMessage(Handler.java:519)
      at android.view.ViewRootImpl.dispatchWindowAnimationStopped(ViewRootImpl.java:6273)
      at android.view.ViewRootImpl$W.onAnimationStopped(ViewRootImpl.java:6842)
      at android.view.IWindow$Stub.onTransact(IWindow.java:244)
      at android.os.Binder.execTransact(Binder.java:453)
03-09 17:08:12.550 2798-2811/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
    at android.os.Handler.enqueueMessage(Handler.java:631)
    at android.os.Handler.sendMessageAtTime(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java:570)
    at android.os.Handler.sendMessage(Handler.java:507)
    at android.view.ViewRootImpl.windowFocusChanged(ViewRootImpl.java:6231)
    at android.view.ViewRootImpl$W.windowFocusChanged(ViewRootImpl.java:6736)
    at android.view.IWindow$Stub.onTransact(IWindow.java:156)
    at android.os.Binder.execTransact(Binder.java:453)
03-09 17:08:12.636 2798-2809/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
    at android.os.Handler.enqueueMessage(Handler.java:631)
    at android.os.Handler.sendMessageAtTime(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java:570)
    at android.os.Handler.sendMessage(Handler.java:507)
    at android.view.ViewRootImpl.dispatchAppVisibility(ViewRootImpl.java:6218)
    at android.view.ViewRootImpl$W.dispatchAppVisibility(ViewRootImpl.java:6720)
    at android.view.IWindow$Stub.onTransact(IWindow.java:140)
    at android.os.Binder.execTransact(Binder.java:453)
03-09 17:08:12.652 2798-2811/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
    at android.os.Handler.enqueueMessage(Handler.java:631)
    at android.os.Handler.sendMessageAtTime(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java:570)
    at android.os.Handler.sendMessage(Handler.java:507)
    at android.os.Message.sendToTarget(Message.java:416)
    at android.view.ViewRootImpl.dispatchWindowAnimationStarted(ViewRootImpl.java:6268)
    at android.view.ViewRootImpl$W.onAnimationStarted(ViewRootImpl.java:6834)
    at android.view.IWindow$Stub.onTransact(IWindow.java:238)
    at android.os.Binder.execTransact(Binder.java:453)
03-09 17:08:13.053 2798-5884/com.mycompany.myapp W/MessageQueue: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
  java.lang.IllegalStateException: Handler (android.view.ViewRootImpl$ViewRootHandler) {52ab619} sending message to a Handler on a dead thread
    at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
    at android.os.Handler.enqueueMessage(Handler.java:631)
    at android.os.Handler.sendMessageAtTime(Handler.java:600)
    at android.os.Handler.sendMessageDelayed(Handler.java:570)
    at android.os.Handler.sendEmptyMessageDelayed(Handler.java:534)
    at android.os.Handler.sendEmptyMessage(Handler.java:519)
    at android.view.ViewRootImpl.dispatchWindowAnimationStopped(ViewRootImpl.java:6273)
    at android.view.ViewRootImpl$W.onAnimationStopped(ViewRootImpl.java:6842)
    at android.view.IWindow$Stub.onTransact(IWindow.java:244)
    at android.os.Binder.execTransact(Binder.java:453)

Do you have an idea of what's can cause that? Thanks!

@yfuks
Copy link
Contributor

yfuks commented Mar 9, 2016

com.facebook.react.bridge.ObjectAlreadyConsumedException: Receiving map already consumed

The WritableNativeMap response is already consumed. Don't know why. I'm on the case :)

@yfuks
Copy link
Contributor

yfuks commented Mar 9, 2016

I'm not able to reproduce. Tested on simulator api 23 and on real device api 17.

What is your device ?

@zoontek
Copy link
Author

zoontek commented Mar 9, 2016

I've got the problem on a OnePlus One (android 5.1) and a Nexus 5 (android 6)

@yfuks
Copy link
Contributor

yfuks commented Mar 9, 2016

Tested on a Nexus 5 Android 6.0 still not able to reproduce...

@zoontek
Copy link
Author

zoontek commented Mar 10, 2016

Maybe it can't be reproduce on RN 0.21. I will update and try it a again.

@lwhiteley
Copy link

This happened to me when i was trying to push the same map to a WritableArray twice by mistake in a loop.

for eg.

Bad code:

WritableArray array = Arguments.createArray();
WritableMap map = Arguments.createMap();
    while (condition) {
      map.putString("somevalue", value);
      array.pushMap(map);
    }

The code should have been:

WritableArray array = Arguments.createArray();
    while (condition) {
     WritableMap map = Arguments.createMap();
      map.putString("somevalue", value);
      array.pushMap(map);
    }

As you can see in the bad example, the variable map was not inside the loop and wasnt being recreated on each iteration so it had the same reference.

It seems the WritableArray is aware of the references of the objects and doesn't allow you to add a map twice.

hope this helps or gives some insight

@marcshilling
Copy link
Contributor

@lwhiteley does that fix the crash? Want to submit a PR?

@yfuks
Copy link
Contributor

yfuks commented Apr 6, 2016

I just made a little update in the project to fix this. As @lwhiteley just tell. Hope this will fix the issue !

f134b91#diff-e2ac0feb8ce151bd872a7c4ab6b4801dR170

@yfuks
Copy link
Contributor

yfuks commented Apr 18, 2016

No response, i close.

@yfuks yfuks closed this as completed Apr 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants