mylisabox / flutter_mjpeg

Flutter widget to show mjpeg stream from URL
BSD 2-Clause "Simplified" License
32 stars 24 forks source link

Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe. #8

Closed YowFung closed 3 years ago

YowFung commented 4 years ago

I using this Mjpeg widget but it throws the following exception continuously...

E/flutter (30368): [ERROR:flutter/lib/ui/ui_dart_state.cc(171)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
E/flutter (30368): At this point the state of the widget's element tree is no longer stable.
E/flutter (30368): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.     
E/flutter (30368): #0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3849:9)
E/flutter (30368): #1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3863:6)
E/flutter (30368): #2      Element.dependOnInheritedWidgetOfExactType (package:flutter/src/widgets/framework.dart:3905:12)
E/flutter (30368): #3      HookElement.dependOnInheritedWidgetOfExactType (package:flutter_hooks/src/framework.dart:461:18)
E/flutter (30368): #4      DefaultAssetBundle.of (package:flutter/src/widgets/basic.dart:5641:47)
E/flutter (30368): #5      createLocalImageConfiguration (package:flutter/src/widgets/image.dart:54:32)
E/flutter (30368): #6      precacheImage (package:flutter/src/widgets/image.dart:111:37)
E/flutter (30368): #7      _StreamManager.updateStream.<anonymous closure> (package:flutter_mjpeg/src/mjpeg.dart:165:21)
E/flutter (30368): #8      _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (30368): #9      _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (30368): #10     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (30368): #11     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter (30368): #12     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter (30368): #13     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (30368): #14     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (30368): #15     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (30368): #16     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter (30368): #17     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter (30368): #18     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (30368): #19     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (30368): #20     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (30368): #21     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter (30368): #22     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter (30368): #23     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter (30368): #24     _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter (30368): #25     _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter (30368): #26     _HttpParser._doParse (dart:_http/http_parser.dart:808:28)
E/flutter (30368): #27     _HttpParser._parse (dart:_http/http_parser.dart:323:7)
E/flutter (30368): #28     _HttpParser._onData (dart:_http/http_parser.dart:852:5)
E/flutter (30368): #29     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter (30368): #30     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (30368): #31     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (30368): #32     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter (30368): #33     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter (30368): #34     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter (30368): #35     _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter (30368): #36     _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter (30368): #37     _Socket._onData (dart:io-patch/socket_patch.dart:2044:41)
E/flutter (30368): #38     _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (30368): #39     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (30368): #40     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (30368): #41     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter (30368): #42     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter (30368): #43     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter (30368): #44     _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter (30368): #45     _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter (30368): #46     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1580:33)
E/flutter (30368): #47     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1076:14)
E/flutter (30368): #48     _microtaskLoop (dart:async/schedule_

or

E/flutter ( 3948): [ERROR:flutter/lib/ui/ui_dart_state.cc(171)] Unhandled Exception: A ValueNotifier<dynamic> was used after being disposed.
E/flutter ( 3948): Once you have called dispose() on a ValueNotifier<dynamic>, it can no longer be used.
E/flutter ( 3948): #0      ChangeNotifier._debugAssertNotDisposed.<anonymous closure> (package:flutter/src/foundation/change_notifier.dart:117:9)
E/flutter ( 3948): #1      ChangeNotifier._debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:123:6)
E/flutter ( 3948): #2      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:217:12)
E/flutter ( 3948): #3      ValueNotifier.value= (package:flutter/src/foundation/change_notifier.dart:292:5)
E/flutter ( 3948): #4      _StreamManager.updateStream (package:flutter_mjpeg/src/mjpeg.dart:187:18)
E/flutter ( 3948): <asynchronous suspension>
E/flutter ( 3948): #5      Mjpeg.build.<anonymous closure> (package:flutter_mjpeg/src/mjpeg.dart:70:15)
E/flutter ( 3948): #6      _EffectHookState.scheduleEffect (package:flutter_hooks/src/primitives.dart:177:27)
E/flutter ( 3948): #7      _EffectHookState.initHook (package:flutter_hooks/src/primitives.dart:151:5)
E/flutter ( 3948): #8      _extension#0._createHookState (package:flutter_hooks/src/framework.dart:301:9)
E/flutter ( 3948): #9      _extension#0._appendHook (package:flutter_hooks/src/framework.dart:312:20)
E/flutter ( 3948): #10     HookElement._use (package:flutter_hooks/src/framework.dart:421:7)
E/flutter ( 3948): #11     Hook.use (package:flutter_hooks/src/framework.dart:148:44)
E/flutter ( 3948): #12     use (package:flutter_hooks/src/framework.dart:19:32)
E/flutter ( 3948): #13     useEffect (package:flutter_hooks/src/primitives.dart:131:3)
E/flutter ( 3948): #14     Mjpeg.build (package:flutter_mjpeg/src/mjpeg.dart:67:5)
E/flutter ( 3948): #15     StatelessElement.build (package:flutter/src/widgets/framework.dart:4644:28)
E/flutter ( 3948): #16     HookElement.build (package:flutter_hooks/src/framework.dart:401:27)
E/flutter ( 3948): #17     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4570:15)
E/flutter ( 3948): #18     Element.rebuild (package:flutter/src/widgets/framework.dart:4286:5)
E/flutter ( 3948): #19     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4549:5)
E/flutter ( 3948): #20     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4544:5)
E/flutter ( 3948): #21     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3512:14)
E/flutter ( 3948): #22     Element.updateChild (package:flutter/src/widgets/framework.dart:3270:18)
E/flutter ( 3948): #23     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6061:14)
E/flutter ( 3948): #24     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3512:14)
E/flutter ( 3948): #25     Element.updateChild (package:flutter/src/widgets/framework.dart:3270:18)
E/flutter ( 3948): #26     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6061:14)
E/flutter ( 3948): #27     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3512:14)
E/flutter ( 3948): #28     Element.updateChild (package:flutter/src/widgets/framework.dart:3270:18)
E/flutter ( 3948): #29     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6061:14)
E/flutter ( 3948): #30     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3512:14)
E/flutter ( 3948): #31     Element.updateChild (package:flutter/src/widgets/framework.dart:3270:18)
E/flutter ( 3948): #32     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4595:16)
E/flutter ( 3948): #33     Element.rebuild (package:flutter/src/widgets/framework.dart:4286:5)
E/flutter ( 3948): #34     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4549:5)
E/flutter ( 3948): #35     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4544:5)
E/flutter ( 3948): #36     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3512:14)
E/flutter ( 3948): #37     Element.updateChild (package:flutter/src/widgets/framework.dart:3270:18)
E/flutter ( 3948): #38     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6061:14)
E/flutter ( 3948): #39     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3512:14)
E/flutter ( 3948): #40     Element.updateChild (package:flutter/src/widgets/framework.dart:3270:18)
E/flutter ( 3948): #41     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6061:14)
E/flutter ( 3948): #42     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3512:14)
E/flutter ( 3948): #43     Element.updateChild (package:flutter/src/widgets/framework.dart:3270:18)
E/flutter ( 3948): #44     ComponentElement.performRebuild (package:flutter/src/widgets/framew

In addition, when I include this Mjpeg widget in ListView (at least 5 items), my application runs very very slowly. Is it because of the poor performance of this widget?

My code snippet: ```dart import 'package:flutter/material.dart'; import 'package:flutter_mjpeg/flutter_mjpeg.dart'; class MyHomePage extends StatelessWidget { Widget build(BuildContext context) { var urlList = List.generate(255, (index) => "http://192.168.1.$index/stream"); return Scaffold( appBar: AppBar(title: Text("MJPEG")), body: Center( child: Container( width: double.infinity, height: 120, color: Colors.black12, child: ListView.builder( scrollDirection: Axis.horizontal, itemCount: urlList.length, itemBuilder: (BuildContext context, int index) => Container( margin: EdgeInsets.only(right: 10), width: 214, height: 120, color: Colors.black, child: Mjpeg( stream: urlList[index], isLive: true, fit: BoxFit.fill, error: (_, error) => Center(child: Text(error.toString(), style: TextStyle(color: Colors.red))), loading: (_) => Center(child: CircularProgressIndicator()) ) ) ) ) ) ); } } ```
flutter doctor -v ```txt [√] Flutter (Channel master, 1.22.0-10.0.pre.39, on Microsoft Windows [Version 10.0.18362.1016], locale zh-CN) • Flutter version 1.22.0-10.0.pre.39 at D:\SDK\Flutter\stable • Framework revision a8281e31af (3 days ago), 2020-09-01 10:57:59 -0700 • Engine revision 165abef0a2 • Dart version 2.10.0 (build 2.10.0-77.0.dev) • Pub download mirror https://pub.flutter-io.cn • Flutter download mirror https://storage.flutter-io.cn [√] Android toolchain - develop for Android devices (Android SDK version 30.0.0) • Android SDK at D:/SDK/Android • Platform android-30, build-tools 30.0.0 • ANDROID_HOME = D:\SDK\Android • ANDROID_SDK_ROOT = D:\SDK\Android • Java binary at: C:\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted. [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.6.3) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community • Visual Studio Community 2019 version 16.6.30225.117 • Windows 10 SDK version 10.0.18362.0 [√] Android Studio (version 4.0) • Android Studio at C:\Android\Android Studio • Flutter plugin version 46.0.2 • Dart plugin version 193.7361 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [√] VS Code (version 1.48.2) • VS Code at C:\Users\YowFu\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.14.0 [√] Connected device (2 available) • AGS2 AL00 (mobile) • 62RBB19920101383 • android-arm64 • Android 9 (API 28) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.18362.1016] • No issues found! ```
jaumard commented 4 years ago

Hi,

Never got that ! I'll try to take a look asap!

For the performance are you talking in debug or release mode ? Because yes performances are shity (app wide) in debug mode, but I don't have any trouble in release mode.

YowFung commented 4 years ago

@jaumard Yep, sorry. I have tried using it in my other simple application. It runs fast. So I think maybe my previous project that was too long, and the performance was affected.

jaumard commented 4 years ago

No problem at :) I'm using it in a gridView on my app, only tried with 2/3 streams but with other items on the grid with no issues so far ^^

YowFung commented 4 years ago

@jaumard, You can try the following suggestions to reproduce the issue:

YowFung commented 4 years ago

Make the Mjpeg widget visible, and then invisible, and then visible again, the issue will take place.

jaumard commented 3 years ago

Should be fixed on 1.3.0