m-r-davari / flutter_3d_controller

A Flutter package for rendering interactive 3D models in different formats(glb, gltf, fbx, obj), with ability to control animations, textures and camera.
https://pub.dev/packages/flutter_3d_controller
MIT License
78 stars 8 forks source link

DIspose not present #2

Closed Maqcel closed 5 months ago

Maqcel commented 5 months ago

Hi I was trying out the package for the POC and I've managed to expirience the memory related issues. After using the hot reload feature the app leaks the controller and setState is called after the widget is not mounted in the tree.

[log] setState() called after dispose(): ModelViewerState#c07b1(lifecycle state: defunct, not mounted)
      This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
      The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
      This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
[log] #0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1167:9)
      #1      State.setState (package:flutter/src/widgets/framework.dart:1202:6)
      #2      ModelViewerState._initController (package:flutter_3d_controller/src/modules/model_viewer/model_viewer_mobile.dart:219:5)
      <asynchronous suspension>
m-r-davari commented 5 months ago

Hi, the issue you mentioned does not exist in any of the Android, iOS, or Web platforms, and it also works fine during hot reload. The error 'setState() called after dispose()' usually occurs due to improper use of states in Flutter. If you are certain there is an issue with the package, please provide more details and a test scenario to enable us to reproduce the issue. Alternatively, you can run and check the example of the package to learn how to use it properly.

Maqcel commented 5 months ago

I managed to run it on different device in other IDE I think that VSC managed to setState on dismounted context on file save.