olexale / arkit_flutter_plugin

ARKit Flutter Plugin
MIT License
797 stars 225 forks source link

Crashing on multiple views #117

Open tantzygames opened 3 years ago

tantzygames commented 3 years ago

I see this was looked at in #89 but with 0.6.0 I'm getting a crash around view 10 or 11 on iPhone 6s

I've tried creating a new ARKitSceneView and disposing the controller each time, as well as caching the ARKitSceneView and controller but both have the same problem.

Up to 8-9 views it seems fine, then it is slower to open and slower to detect which indicates it will crash on this or the next open.

ARCore on Android survives over 20 views. A fallback to reading QR Codes also continues past 20 views on both iOS and Android.

void onARKitViewCreated(ARKitController arkitController) {
    arkitController = arkitController;
    arkitController.onAddNodeForAnchor = onAnchorWasFound;

  }
  void onAnchorWasFound(ARKitAnchor anchor) {
    if (anchor is ARKitImageAnchor) {
      print('got anchor ${anchor.referenceImageName}');
      for (var p in event.trailData.places.values) {
        if (p.image == anchor.referenceImageName) {
            placeVisited(p);
            print('*** Tracking AR Image ${p.name} ***');
        }
      }
    }
  }
Widget arKit()
  {
    if (arKitImages == null) {
      arKitImages = new List<ARKitReferenceImage>();
      for (var p in event.trailData.places.values) {
        if (p.id != event.trailData.rewardPlace) {
          arKitImages.add(ARKitReferenceImage(
            name: p.image,
            physicalWidth: 0.1,
          ));
        }
      }
    }
    return ARKitSceneView(
      //configuration: ARKitConfiguration.imageTracking,
      detectionImages: arKitImages,
      onARKitViewCreated: onARKitViewCreated,
    );
  }

Changing to imageTracking and limiting the tracked images doesn't crash until around view 20:

return ARKitSceneView(
      configuration: ARKitConfiguration.imageTracking,
      trackingImages: arKitImages,
      onARKitViewCreated: onARKitViewCreated,
      autoenablesDefaultLighting: false,
      maximumNumberOfTrackedImages: 1,

    );