Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] FlutterEngine textureFrameAvailable crash #181

Open
JulienDev opened this issue Nov 15, 2024 · 20 comments
Open

[iOS] FlutterEngine textureFrameAvailable crash #181

JulienDev opened this issue Nov 15, 2024 · 20 comments

Comments

@JulienDev
Copy link

Describe the bug
Some iOS users are experiencing a crash on iOS and iPadOS (all versions impacted). I can't provide full logs because I'm not able to reproduce on my side. The Crashlytics stacktrace is always the same for all impacted users.

Stacktrace

          Crashed: mdk.vdec0@0x16e73f000
0  Flutter                        0x15dac -[FlutterEngine textureFrameAvailable:] + 53 (weak_ptr.h:53)
1  Flutter                        0x4ff04 -[FlutterTextureRegistryRelay textureFrameAvailable:] + 34 (FlutterTextureRegistryRelay.mm:34)
2  fvp                            0xe85c void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:ne180100]<TexturePlayer::TexturePlayer(long long, int, int, NSObject<FlutterTextureRegistry>*)::'lambda'(void*)&, void*>(TexturePlayer::TexturePlayer(long long, int, int, NSObject<FlutterTextureRegistry>*)::'lambda'(void*)&, void*&&) + 471 (mutex:471)
3  fvp                            0xe6a4 mdk::Player::setRenderCallback(std::__1::function<void (void*)> const&)::'lambda'(void*, void*)::__invoke(void*, void*) + 41 (lock_guard.h:41)
4  mdk                            0x95160 std::__1::function<void (mdk::abi::FrameProcessor<mdk::abi::VideoFrame>*)>::operator()(mdk::abi::FrameProcessor<mdk::abi::VideoFrame>*) const + 426 (function.h:426)
5  mdk                            0xf1f28 mdk::abi::VideoRenderer::update() + 471 (mutex:471)
6  mdk                            0xf1e24 mdk::abi::VideoRenderer::process(mdk::abi::VideoFrame const&, mdk::abi::RenderStatistics*) + 1582 (__tree:1582)
7  mdk                            0xdd758 mdk::abi::VideoPresenter::present(mdk::abi::VideoFrame const&, mdk::abi::RenderStatistics*) + 556 (VideoPresenter.cpp:556)
8  mdk                            0xb1a6c std::__1::function<double (mdk::abi::VideoFrame const&, mdk::abi::RenderStatistics*)>::operator()(mdk::abi::VideoFrame const&, mdk::abi::RenderStatistics*) const + 428 (function.h:428)
9  mdk                            0xb2858 mdk::abi::MediaControlPush::onProcessed(mdk::abi::VideoFrame const&, int) + 1521 (MediaControl.cpp:1521)
10 mdk                            0xb18dc mdk::abi::MediaControlPush::onVideoReadInThread(mdk::abi::VideoFrame&, int) + 1192 (MediaControl.cpp:1192)
11 mdk                            0xb1240 mdk::abi::MediaControlPush::onVideoRead(mdk::abi::VideoFrame const&, int) + 1310 (MediaControl.cpp:1310)
12 mdk                            0xb5448 std::__1::__function::__func<mdk::abi::MediaControlPush::updateUniqueReaders()::$_3, std::__1::allocator<mdk::abi::MediaControlPush::updateUniqueReaders()::$_3>, bool (mdk::abi::VideoFrame const&, int)>::operator()(mdk::abi::VideoFrame const&, int&&) + 311 (function.h:311)
13 mdk                            0xa1c68 bool mdk::abi::FrameReader::frameAvailable<mdk::abi::VideoFrame>(mdk::abi::VideoFrame&, int) const + 1050 (FrameReader.cpp:1050)
14 mdk                            0x9d3a4 bool mdk::abi::FrameReaderImpl::decodeLoop<(mdk::abi::MediaType)0>(int, int) + 2577 (FrameReader.cpp:2577)
15 mdk                            0x9a070 void* std::__1::__thread_proxy[abi:nn180100]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, mdk::abi::FrameReaderImpl::startDecodeThread(mdk::abi::FrameReaderImpl::DecLoopState&, mdk::abi::MediaType, int)::$_0>>(void*) + 2738 (FrameReader.cpp:2738)
16 libsystem_pthread.dylib        0x637c _pthread_start + 136
17 libsystem_pthread.dylib        0x1494 thread_start + 8
        
@wang-bin
Copy link
Owner

wang-bin commented Nov 15, 2024

can you provide mdk.framework or ipa so i can know the version? the latest version should fix the crash

@JulienDev
Copy link
Author

Sure, I kept only ios files to make it lighter: mdk.xcframework.zip

@wang-bin
Copy link
Owner

try fvp master branch. btw, how can i test your app?

@JulienDev
Copy link
Author

Thanks I'll try ! The app is this one if you want to test it: https://apps.apple.com/fr/app/iptv-smarters-player-expert/id1641944027

@dinurymomshad
Copy link

dinurymomshad commented Nov 22, 2024

I think I am facing similar issues with iOS as well. Here is the crash log from Xcode during debug. Also, there was no crash log on flutter debug console. Since Xcode was running the error stack was logged there. I streaming RTSP from IP camera.

Dependencies:

video_player: ^2.9.2
fvp: ^0.28.0

Error Log:

*** First throw call stack:
(0x18946108c 0x1867632e4 0x1895674f0 0x23d845334 0x109b66754 0x10984e894 0x10984bb9c 0x109844020 0x1097e6340 0x109853ef0 0x109cd1690 0x109bcb584 0x109c823ec 0x109c83184 0x109751e40 0x109c81afc 0x109c8191c 0x109c9c064 0x1097503f0 0x1097545d4 0x1894933f8 0x18949309c 0x189492bf0 0x1894310fc 0x1894305b8 0x1097546c0 0x109753728 0x1097533b8 0x2106d937c 0x2106d4494)
libc++abi: terminating due to uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSMallocException', reason: '*** -[NSObject allocWithZone:]: attempt to allocate object of class 'MTLDebugRenderCommandEncoder' failed'
*** First throw call stack:
(0x18946108c 0x1867632e4 0x1895674f0 0x23d845334 0x104fe8700 0x104fe8ffc 0x104ff9668 0x104ff89dc 0x104fc2a8c 0x1035c27c4 0x1035c26dc 0x1035c2690 0x1035c263c 0x1035c2610 0x1035c1240 0x1035c0b78 0x1035c0b20 0x1035c0ac0 0x1035c0a60 0x104f996bc 0x104ff635c 0x104ff6254 0x104fe1ad0 0x104fb5fb4 0x104fb6d1c 0x104fb5e24 0x104fb578c 0x104fb9900 0x104fa61c4 0x104fa1900 0x104f9e5cc 0x2106d937c 0x2106d4494)
libc++abi: terminating due to uncaught exception of type NSException

Code:

main.dart

void main() {
  fvp.registerWith(options: {
    'video.decoders': [Platform.isAndroid ? 'mediacodec' : 'videotoolbox'],
    'lowLatency': 2,
  });
  runApp(
    ProviderScope(
      observers: [RiverpodObserver()],
      child: const AppStartupWidget(
        loading: SplashPage(),
        loaded: MyApp(),
      ),
    ),
  );
}

video_player_wrapper.dart


class VideoPlayerWrapper extends StatefulWidget {
  const VideoPlayerWrapper({
    super.key,
    required this.streamURL,
    this.reset,
  });

  final String streamURL;
  final VoidCallback? reset;

  @override
  State<VideoPlayerWrapper> createState() => _VideoPlayerWrapperState();
}

class _VideoPlayerWrapperState extends State<VideoPlayerWrapper> {
  late final VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.networkUrl(
      Uri.parse(widget.streamURL),
      formatHint: VideoFormat.ss,
    )..initialize().then((_) {
        _controller.play();
        setState(() {});
      });
  }

  @override
  dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.center,
      children: [
        if (_controller.value.isInitialized) ...[
          AspectRatio(
            aspectRatio: _controller.value.aspectRatio,
            child: VideoPlayer(_controller),
          )
        ] else ...[
          const Center(child: CircularProgressIndicator()),
        ],
        if (_controller.value.hasError) PlaybackErrorWidget(reset: widget.reset)
      ],
    );
  }
}

@wang-bin
Copy link
Owner

@dinurymomshad what about master branch? I need the stacktrace

@dinurymomshad
Copy link

@dinurymomshad what about master branch? I need the stacktrace

Alright, I will try master branch. Regarding, stackTrace not sure how to log it. Can you help me with an example? Would wrapping the command in main.dart with try-catch work?

@dinurymomshad
Copy link

Most probably this is the debug log:

(lldb) bt
* thread #16, name = 'io.flutter.1.raster', stop reason = signal 2147483647
  * frame #0: 0x00000001d927f274 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000002106daef8 libsystem_pthread.dylib`pthread_kill + 268
    frame #2: 0x0000000191193ad8 libsystem_c.dylib`abort + 128
    frame #3: 0x00000002105fe5b8 libc++abi.dylib`abort_message + 132
    frame #4: 0x00000002105ecbac libc++abi.dylib`demangling_terminate_handler() + 348
    frame #5: 0x000000018677ee04 libobjc.A.dylib`_objc_terminate() + 156
    frame #6: 0x00000002105fd87c libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x00000002106010ac libc++abi.dylib`__cxa_rethrow + 204
    frame #8: 0x000000018677a650 libobjc.A.dylib`objc_exception_rethrow + 44
    frame #9: 0x000000018943067c CoreFoundation`CFRunLoopRunSpecific + 768
    frame #10: 0x00000001073286c0 Flutter`fml::MessageLoopDarwin::Run() + 88
    frame #11: 0x0000000107327728 Flutter`std::_fl::__function::__func<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0, std::_fl::allocator<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0>, void ()>::operator()() + 180
    frame #12: 0x00000001073273b8 Flutter`fml::ThreadHandle::ThreadHandle(std::_fl::function<void ()>&&)::$_0::__invoke(void*) + 36
    frame #13: 0x00000002106d937c libsystem_pthread.dylib`_pthread_start + 136
    (lldb) bt
* thread #16, name = 'io.flutter.1.raster', stop reason = signal 2147483647
  * frame #0: 0x00000001d927f274 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000002106daef8 libsystem_pthread.dylib`pthread_kill + 268
    frame #2: 0x0000000191193ad8 libsystem_c.dylib`abort + 128
    frame #3: 0x00000002105fe5b8 libc++abi.dylib`abort_message + 132
    frame #4: 0x00000002105ecbac libc++abi.dylib`demangling_terminate_handler() + 348
    frame #5: 0x000000018677ee04 libobjc.A.dylib`_objc_terminate() + 156
    frame #6: 0x00000002105fd87c libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x00000002106010ac libc++abi.dylib`__cxa_rethrow + 204
    frame #8: 0x000000018677a650 libobjc.A.dylib`objc_exception_rethrow + 44
    frame #9: 0x000000018943067c CoreFoundation`CFRunLoopRunSpecific + 768
    frame #10: 0x00000001073286c0 Flutter`fml::MessageLoopDarwin::Run() + 88
    frame #11: 0x0000000107327728 Flutter`std::_fl::__function::__func<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0, std::_fl::allocator<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0>, void ()>::operator()() + 180
    frame #12: 0x00000001073273b8 Flutter`fml::ThreadHandle::ThreadHandle(std::_fl::function<void ()>&&)::$_0::__invoke(void*) + 36
    frame #13: 0x00000002106d937c libsystem_pthread.dylib`_pthread_start + 136(lldb) bt
* thread #16, name = 'io.flutter.1.raster', stop reason = signal 2147483647
  * frame #0: 0x00000001d927f274 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000002106daef8 libsystem_pthread.dylib`pthread_kill + 268
    frame #2: 0x0000000191193ad8 libsystem_c.dylib`abort + 128
    frame #3: 0x00000002105fe5b8 libc++abi.dylib`abort_message + 132
    frame #4: 0x00000002105ecbac libc++abi.dylib`demangling_terminate_handler() + 348
    frame #5: 0x000000018677ee04 libobjc.A.dylib`_objc_terminate() + 156
    frame #6: 0x00000002105fd87c libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x00000002106010ac libc++abi.dylib`__cxa_rethrow + 204
    frame #8: 0x000000018677a650 libobjc.A.dylib`objc_exception_rethrow + 44
    frame #9: 0x000000018943067c CoreFoundation`CFRunLoopRunSpecific + 768
    frame #10: 0x00000001073286c0 Flutter`fml::MessageLoopDarwin::Run() + 88
    frame #11: 0x0000000107327728 Flutter`std::_fl::__function::__func<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0, std::_fl::allocator<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0>, void ()>::operator()() + 180
    frame #12: 0x00000001073273b8 Flutter`fml::ThreadHandle::ThreadHandle(std::_fl::function<void ()>&&)::$_0::__invoke(void*) + 36
    frame #13: 0x00000002106d937c libsystem_pthread.dylib`_pthread_start + 136(lldb) bt
* thread #16, name = 'io.flutter.1.raster', stop reason = signal 2147483647
  * frame #0: 0x00000001d927f274 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000002106daef8 libsystem_pthread.dylib`pthread_kill + 268
    frame #2: 0x0000000191193ad8 libsystem_c.dylib`abort + 128
    frame #3: 0x00000002105fe5b8 libc++abi.dylib`abort_message + 132
    frame #4: 0x00000002105ecbac libc++abi.dylib`demangling_terminate_handler() + 348
    frame #5: 0x000000018677ee04 libobjc.A.dylib`_objc_terminate() + 156
    frame #6: 0x00000002105fd87c libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x00000002106010ac libc++abi.dylib`__cxa_rethrow + 204
    frame #8: 0x000000018677a650 libobjc.A.dylib`objc_exception_rethrow + 44
    frame #9: 0x000000018943067c CoreFoundation`CFRunLoopRunSpecific + 768
    frame #10: 0x00000001073286c0 Flutter`fml::MessageLoopDarwin::Run() + 88
    frame #11: 0x0000000107327728 Flutter`std::_fl::__function::__func<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0, std::_fl::allocator<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0>, void ()>::operator()() + 180
    frame #12: 0x00000001073273b8 Flutter`fml::ThreadHandle::ThreadHandle(std::_fl::function<void ()>&&)::$_0::__invoke(void*) + 36
    frame #13: 0x00000002106d937c libsystem_pthread.dylib`_pthread_start + 136
    ```

@wang-bin
Copy link
Owner

wang-bin commented Nov 22, 2024

run bt after crash. the ide will also show the stack. show me the screenshot or google how to show backtrace in xcode

@dinurymomshad
Copy link

Weird, when I try to run this:

  fvp:
    git:
      url: https://github.com/wang-bin/fvp.git
      ref: master

I got the following error:

/Users/dinury/src/flutter/bin/flutter --no-color pub get
Resolving dependencies...
Could not find a file named "pubspec.yaml" in https://github.com/wang-bin/fvp.git 9c935f658e248e30f9c9f85dbc314ea032246e1f.
Process finished with exit code 1

@dinurymomshad
Copy link

Over time the memory consumption is increasing. Feels like this is what causing the stream to crash.

Screenshot 2024-11-22 at 2 54 19 PM

@wang-bin
Copy link
Owner

Over time the memory consumption is increasing. Feels like this is what causing the stream to crash.

Screenshot 2024-11-22 at 2 54 19 PM

no, i only need backtrace

@dinurymomshad
Copy link

Over time the memory consumption is increasing. Feels like this is what causing the stream to crash.
Screenshot 2024-11-22 at 2 54 19 PM

no, i only need backtrace

Backtrace:

* thread #17, name = 'io.flutter.1.raster', stop reason = signal SIGABRT
  * frame #0: 0x00000001d927f274 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000002106daef8 libsystem_pthread.dylib`pthread_kill + 268
    frame #2: 0x0000000191193ad8 libsystem_c.dylib`abort + 128
    frame #3: 0x00000002105fe5b8 libc++abi.dylib`abort_message + 132
    frame #4: 0x00000002105ecbac libc++abi.dylib`demangling_terminate_handler() + 348
    frame #5: 0x000000018677ee04 libobjc.A.dylib`_objc_terminate() + 156
    frame #6: 0x00000002105fd87c libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x00000002106010ac libc++abi.dylib`__cxa_rethrow + 204
    frame #8: 0x000000018677a650 libobjc.A.dylib`objc_exception_rethrow + 44
    frame #9: 0x000000018943067c CoreFoundation`CFRunLoopRunSpecific + 768
    frame #10: 0x00000001093546c0 Flutter`fml::MessageLoopDarwin::Run() + 88
    frame #11: 0x0000000109353728 Flutter`std::_fl::__function::__func<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0, std::_fl::allocator<fml::Thread::Thread(std::_fl::function<void (fml::Thread::ThreadConfig const&)> const&, fml::Thread::ThreadConfig const&)::$_0>, void ()>::operator()() + 180
    frame #12: 0x00000001093533b8 Flutter`fml::ThreadHandle::ThreadHandle(std::_fl::function<void ()>&&)::$_0::__invoke(void*) + 36
    frame #13: 0x00000002106d937c libsystem_pthread.dylib`_pthread_start + 136

Screenshot:

Screenshot 2024-11-22 at 3 26 48 PM

@dinurymomshad
Copy link

@wang-bin I have confirmed that its crashing on iOS due to some kind of memory leak issue. Right now I am running the app using Fijkplayer (which I was using previously), the memory consumption is consistent between 450-490mb.

Attaching a screen record:

Screen.Recording.2024-11-22.at.3.36.41.PM.mov

@wang-bin
Copy link
Owner

wang-bin commented Nov 22, 2024

@dinurymomshad i had similar issue running on macos and ios in xcode, but no memory leak if run without xcode. your crash is different from current issue, so please open another issue. can you show me the log? you can enable log following issue template

@JulienDev
Copy link
Author

@wang-bin The new version using the master branch is being reviewed right now. I'll let you know in a few days if the problem is solved

@JulienDev
Copy link
Author

@wang-bin The crash is still happening, and I noticed one interesting thing: It happens 100% of the time when the app is in the background. However, I'm not able to reproduce it on my side.

@wang-bin
Copy link
Owner

@wang-bin The crash is still happening, and I noticed one interesting thing: It happens 100% of the time when the app is in the background. However, I'm not able to reproduce it on my side.

I can't reproduce it on my simulator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants