wasabia / three_dart

three.js rewrite by Dart, Dart 3D library. an easy to use, lightweight, cross-platform, general purpose 3D library.
MIT License
444 stars 77 forks source link

IOS app crashes after I pop the three.dart page. #137

Closed hasnentai closed 11 months ago

hasnentai commented 11 months ago

Here is the Error I see in the log when I pop the page out and the app crashes.

Can you look into it @Knightro63 ?

flutter:
2
flutter_gl/SwiftFlutterGlPlugin.swift:105: Fatal error: Unexpectedly found nil while unwrapping an Optional value
* thread #1, queue = 'com.apple.main-thread', stop reason = Fatal error: Unexpectedly found nil while unwrapping an Optional value
frame #0: 0x0000000185958198 libswiftCore.dylib`_swift_runtime_on_report
libswiftCore.dylib`:
->  0x185958198 <+0>: ret
libswiftCore.dylib`:
    0x18595819c <+0>: b      0x185958198               ; _swift_runtime_on_report
libswiftCore.dylib`:
    0x1859581a0 <+0>: adrp   x8, 365701
    0x1859581a4 <+4>: ldrb   w0, [x8, #0xabc]

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.3, on macOS 13.4.1 22F82 darwin-arm64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.80.1)
[✓] VS Code (version 1.71.0)
[✓] Connected device (3 available)            
[✓] Network resources
Knightro63 commented 11 months ago

Hi @hasnentai,

This happens if three3dRender.updateTexture(sourceTexture); is ran after dispose.

Here is an example to prevent this from happening.

  late FlutterGlPlugin three3dRender;
  THREE.WebGLRenderer? renderer;
  bool disposed = false;

  @override
  void dispose() {
    disposed = true;
    three3dRender.dispose();
    super.dispose();
  }

  void animate() {
    if (!mounted || disposed) {
      return;
    }

    renderer!.render(scene, camera);
    three3dRender.gl.flush();
    if (!kIsWeb) {
      three3dRender.updateTexture(sourceTexture);
    }

    Future.delayed(const Duration(milliseconds: 40), () {
      animate();
    });
  }

Hope this helps.

hasnentai commented 11 months ago

Thank you this is working fine