nmfisher / thermion

3D rendering toolkit for Dart and/or Flutter
https://thermion.dev
Apache License 2.0
125 stars 10 forks source link

Hot restart on Android throws exception #53

Open Hannnes1 opened 4 months ago

Hannnes1 commented 4 months ago

Doing a hot restart on android throws the following exception:

E/flutter (18641): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(TEXTURE_EXISTS, Texture already exist. Make sure you call destroyTexture first, null, null)
E/flutter (18641): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
E/flutter (18641): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
E/flutter (18641): <asynchronous suspension>
E/flutter (18641): #2      ThermionFlutterFFI.createTexture (package:thermion_flutter_ffi/thermion_flutter_ffi.dart:126:18)
E/flutter (18641): <asynchronous suspension>
E/flutter (18641): #3      _ThermionWidgetState.initState.<anonymous closure> (package:thermion_flutter/thermion/widgets/thermion_widget.dart:48:18)
E/flutter (18641): <asynchronous suspension>

During my limited investigation I found this issue, which I think is the reason: flutter/flutter#75528

Reproducible example:

import 'package:flutter/material.dart';
import 'package:thermion_flutter/thermion_flutter.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  ThermionViewer? _viewer;

  @override
  void initState() {
    super.initState();

    ThermionFlutterPlugin.createViewer().then((value) {
      _viewer = value;

      value.loadIbl('assets/custom_ibl.ktx');
      value.loadGlb('assets/duck.glb');

      value.setCameraPosition(0, 0, -1);

      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: _viewer == null
              ? const CircularProgressIndicator()
              : ThermionWidget(
                  viewer: _viewer!,
                ),
        ),
      ),
    );
  }
}