Skip to content

NullPointerException in ArCoreView on dispose and recreate #233

@Akapohn

Description

@Akapohn

First, I would like to thank you for your excellent and helpful plugin. However, I found a problem where the app crashes when disposing and recreating the ArCoreView. Here are the error logs and the solution I found.

Error Logs

E/flutter (11682): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, null cannot be cast to non-null type android.view.View, null, java.lang.NullPointerException: null cannot be cast to non-null type android.view.View
E/flutter (11682):      at com.difrancescogianmarco.arcore_flutter_plugin.ArCoreView.getView(ArCoreView.kt:512)
E/flutter (11682):      at io.flutter.plugin.platform.VirtualDisplayController.getView(VirtualDisplayController.java:278)
E/flutter (11682):      at io.flutter.plugin.platform.PlatformViewsController$1.dispose(PlatformViewsController.java:260)
E/flutter (11682):      at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.dispose(PlatformViewsChannel.java:150)
E/flutter (11682):      at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:58)
E/flutter (11682):      at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/flutter (11682):      at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/flutter (11682):      at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (11682):      at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (11682):      at android.os.Handler.handleCallback(Handler.java:958)
E/flutter (11682):      at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (11682):      at android.os.Looper.loopOnce(Looper.java:230)
E/flutter (11682):      at android.os.Looper.loop(Looper.java:319)
E/flutter (11682):      at android.app.ActivityThread.main(ActivityThread.java:8919)
E/flutter (11682):      at java.lang.reflect.Method.invoke(Native Method)
E/flutter (11682):      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
E/flutter (11682):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
E/flutter (11682): )

Revise getView() Function in ArCoreView.kt and BaseArCoreView.kt

override fun getView(): View? {
        return arSceneView as? View
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions