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

ConcurrentModificationException in VirtualStickManager when calling sendVirtualStickAdvancedParam with Mini 3 #405

Closed
brien-crean opened this issue Aug 21, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@brien-crean
Copy link

brien-crean commented Aug 21, 2024

Issue Summary

When controlling a Mini 3 with sendVirtualStickAdvancedParam(), a ConcurrentModificationException is randomly thrown. This might be due to the collection being modified in an unsafe way while it is being iterated over.

Environment

  • Device: DJI Mini 3
  • SDK Version: 5.9.2
  • Android Version: 13

Expected Behavior

sendVirtualStickAdvancedParam() should safely send virtual stick parameters without causing a ConcurrentModificationException.

Actual Behavior

The following exception is thrown randomly when using sendVirtualStickAdvancedParam():

Fatal Exception: java.util.ConcurrentModificationException:
   at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1029)
   at java.util.ArrayList$Itr.next(ArrayList.java:982)
   at dji.v5.manager.aircraft.virtualstick.VirtualStickManager.co_a(VirtualStickManager.java:14)
   at dji.v5.manager.aircraft.virtualstick.VirtualStickManager$2.onSuccess(VirtualStickManager.java:4)
   at dji.v5.common.utils.CallbackUtils.onSuccess(CallbackUtils.java:2)
   at dji.v5.manager.KeyManager$2.onSuccess(KeyManager.java:3)
   at dji.sdk.keyvalue.co_a.co_a(DJIKeyManager.java:20)
   at dji.sdk.keyvalue.-$$Lambda$-U1PAWv6QmqxJJfXN77VwAyEMos.run(:6)
   at android.os.Handler.handleCallback(Handler.java:942)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loopOnce(Looper.java:201)
   at android.os.Looper.loop(Looper.java:288)
   at android.app.ActivityThread.main(ActivityThread.java:7872)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Steps to Reproduce

Use the sendVirtualStickAdvancedParam() function on a DJI Mini 3.
Monitor for ConcurrentModificationException during the execution of this method. Although note that it happens very randomly and intermittently.

Additional Notes

I noticed that there have been other issues related to ConcurrentModificationException reported and resolved in newer SDK versions. It is possible that the VirtualStickManager module might need to be adjusted to ensure better thread safety?

@dji-dev
Copy link
Contributor

dji-dev commented Aug 22, 2024

Agent comment from yating.liao in Zendesk ticket #115256:

You cant to try using the VirtualStickManager interface outside of the onSuccess callback.

°°°

@brien-crean
Copy link
Author

Agent comment from yating.liao in Zendesk ticket #115256:You cant to try using the VirtualStickManager interface outside of the onSuccess callback.

°°°

@dji-dev Perhaps I explained poorly. I am not using the VirtualStickManager interface outside of the onSuccess callback. I am not referencing it directly. I am calling sendVirtualStickAdvancedParam which requires calling VirtualStickManager.getInstance() e.g.

Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate({
  try {
    VirtualStickManager.getInstance().sendVirtualStickAdvancedParam(vsParam)
  } catch (e: Exception) {
      Log.e("Error", e.message)
  }
  }, 0, 50, TimeUnit.MILLISECONDS)

The following exception is thrown intermittently when using sendVirtualStickAdvancedParam():

Fatal Exception: java.util.ConcurrentModificationException:
   at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1029)
   at java.util.ArrayList$Itr.next(ArrayList.java:982)
   at dji.v5.manager.aircraft.virtualstick.VirtualStickManager.co_a(VirtualStickManager.java:14)
   at dji.v5.manager.aircraft.virtualstick.VirtualStickManager$2.onSuccess(VirtualStickManager.java:4)
   at dji.v5.common.utils.CallbackUtils.onSuccess(CallbackUtils.java:2)
   at dji.v5.manager.KeyManager$2.onSuccess(KeyManager.java:3)
   at dji.sdk.keyvalue.co_a.co_a(DJIKeyManager.java:20)
   at dji.sdk.keyvalue.-$$Lambda$-U1PAWv6QmqxJJfXN77VwAyEMos.run(:6)
   at android.os.Handler.handleCallback(Handler.java:942)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loopOnce(Looper.java:201)
   at android.os.Looper.loop(Looper.java:288)
   at android.app.ActivityThread.main(ActivityThread.java:7872)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

This issue happens in 2 out of 10 flights. Your help would be much appreciated in resolving this issue. Thank you

@brien-crean brien-crean changed the title ConcurrentModificationException in VirtualStickManager when controlling Mini 3 ConcurrentModificationException in VirtualStickManager when calling sendVirtualStickAdvancedParam with Mini 3 Aug 22, 2024
@brien-crean
Copy link
Author

@dji-dev I would really appreciate your help on this issue when you have some time. Thanks

@dji-dev
Copy link
Contributor

dji-dev commented Aug 27, 2024

Agent comment from yating.liao in Zendesk ticket #115256:

I apologize for the issues in my previous response.

I have reviewed your code, and it seems there might be a bug in the SDK. You could try using a Timer to implement sending virtual joystick commands at a fixed frequency. I will report this crash to the team.

°°°

@dji-lyt dji-lyt added the bug Something isn't working label Aug 27, 2024
@brien-crean
Copy link
Author

Agent comment from yating.liao in Zendesk ticket #115256:I apologize for the issues in my previous response.

I have reviewed your code, and it seems there might be a bug in the SDK. You could try using a Timer to implement sending virtual joystick commands at a fixed frequency. I will report this crash to the team.

°°°

Thank you very much @dji-dev ! I look forward to hearing if there is a solution or fix to come in the future.

I have tried a Timer but unfortunately I had the same issue intermittently. I switched to using a ScheduledExecutorService as it too can send virtual joystick commands at a fixed frequency plus it is thread safe and easier to manage.

@dji-dev
Copy link
Contributor

dji-dev commented Nov 14, 2024

Agent comment from yating.liao in Zendesk ticket #115256:

The version 5.11 has been released. Currently, we have not encountered the same crash using your method.

°°°

@brien-crean
Copy link
Author

Yes, thank you this seems to be resolved now. We have not seen any crashes related to this since updating to 5.11 either. Thanks again!

@dji-dev
Copy link
Contributor

dji-dev commented Nov 14, 2024

Agent comment from yating.liao in Zendesk ticket #115256:

I’m glad to have resolved your issue.

°°°

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants