1

I've a crash on my nexus 5 Android 6 (hammered/hammered) using CommonsWare library cwac:cam2

when I change the orientation on the recording/photo capturing activities. The bug is systematic on my device.

stacktrace :

E / AndroidRuntime: FATAL EXCEPTION: main
Process: com.m360learning.android, PID: 9637
java.lang.RuntimeException: Unable to start activity ComponentInfo {
 com.m360learning.android / com.commonsware.cwac.cam2.VideoRecorderActivity
}: de.greenrobot.event.EventBusException: Subscriber class com.commonsware.cwac.cam2.CameraFragment already registered to event class com.commonsware.cwac.cam2.CameraController$ControllerReadyEvent
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2476)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java: 4077)
at android.app.ActivityThread. - wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1350)
at android.os.Handler.dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper.java: 148)
at android.app.ActivityThread.main(ActivityThread.java: 5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 616)
Caused by: de.greenrobot.event.EventBusException: Subscriber class com.commonsware.cwac.cam2.CameraFragment already registered to event class com.commonsware.cwac.cam2.CameraController$ControllerReadyEvent
at de.greenrobot.event.EventBus.subscribe(EventBus.java: 179)
at de.greenrobot.event.EventBus.register(EventBus.java: 165)
at de.greenrobot.event.EventBus.register(EventBus.java: 133)
at com.commonsware.cwac.cam2.CameraFragment.onStart(CameraFragment.java: 123)
at android.app.Fragment.performStart(Fragment.java: 2244)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1002)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1148)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1130)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java: 1958)
at android.app.FragmentController.dispatchStart(FragmentController.java: 163)
at android.app.Activity.performStart(Activity.java: 6274)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2476) 
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java: 4077) 
at android.app.ActivityThread. - wrap15(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1350) 
at android.os.Handler.dispatchMessage(Handler.java: 102) 
at android.os.Looper.loop(Looper.java: 148) 
at android.app.ActivityThread.main(ActivityThread.java: 5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 616) 

Thank you very much for the support, the fixes are very quicly implemented.

UMESH0492
  • 1,701
  • 18
  • 31
Renaud Favier
  • 1,645
  • 1
  • 17
  • 33
  • Share some code please? Especially the implementation of the class `CameraFragment` – George Daramouskas Feb 29 '16 at 18:20
  • @GeorgeD: That's coming from a library, which the OP didn't clearly explain. – CommonsWare Feb 29 '16 at 18:21
  • @Renaud: You need to make your questions more suitable for Stack Overflow. *I* understand what you mean here, because I have worked with other questions of yours in this area in the past. However, Stack Overflow is a site for **everyone**, not just you. Each of your questions needs to explain, to somebody who has no idea who you or I are, what your problem is. Just posting a stack trace and a limited explanation of how you got it is insufficient. – CommonsWare Feb 29 '16 at 18:23
  • ok, sorry about that, I should have directly post it on github. – Renaud Favier Feb 29 '16 at 18:28
  • Yes, in this case, this is clearly a bug and could have gone straight to the issue tracker. Basically, if your question is "here's my code, did I do something wrong?", that's suitable for here. But any problem, like a crash, that can be directly reproduced with the demo apps, can go straight to the issue tracker. – CommonsWare Feb 29 '16 at 18:31
  • Ok, I'm reporting the bug on github if you haven't already done it. – Renaud Favier Feb 29 '16 at 18:35

1 Answers1

2

The issue is the you are trying to register the service twice enter code here as you can see in the trace. The service isn't unregistered therefore the easiest option for you is to check whether the service is registered before you register it EventBus.getDefault().isRegistered(...)or check in onStart is event service isn't stopped and therefore still registered. For example:

if (!EventBus.getDefault().isRegistered(this)) {
    EventBus.getDefault().register(this);
}
UMESH0492
  • 1,701
  • 18
  • 31
  • Thank you for that, but, as CommonsWare has mentionned, the question was more about submitting the bug to the CWAC contributors. I wouldn't recommand your solution thought, I think the problem here is more that the activity is not correctly unregistered when it needs to be. – Renaud Favier Feb 29 '16 at 18:33
  • @RenaudFavier, I think it's bug as they haven't handle the orientation change, but as a developer it's an implementation issue. As either you must unregister from that event as documented or check while registering. – UMESH0492 Feb 29 '16 at 19:35