diff --git a/lib/src/impl/agora_rtc_engine_impl.dart b/lib/src/impl/agora_rtc_engine_impl.dart index 766a2df35..9b3e1c4e4 100644 --- a/lib/src/impl/agora_rtc_engine_impl.dart +++ b/lib/src/impl/agora_rtc_engine_impl.dart @@ -312,8 +312,6 @@ class RtcEngineImpl extends rtc_engine_ex_binding.RtcEngineExImpl @override Future release({bool sync = false}) async { - if (_isReleased) return; - // Same as explanation inside `initialize`. We should wait for // the `initialize` function is completed here. if (_initializingCompleter != null && @@ -321,6 +319,10 @@ class RtcEngineImpl extends rtc_engine_ex_binding.RtcEngineExImpl await _initializingCompleter?.future; } + if (!_rtcEngineState.isInitialzed || _isReleased) { + return; + } + _releasingCompleter = Completer(); _rtcEngineStateInternal?.dispose(); @@ -328,8 +330,8 @@ class RtcEngineImpl extends rtc_engine_ex_binding.RtcEngineExImpl await _objectPool.clear(); - await _globalVideoViewController! - .detachVideoFrameBufferManager(irisMethodChannel.getNativeHandle()); + await _globalVideoViewController + ?.detachVideoFrameBufferManager(irisMethodChannel.getNativeHandle()); _globalVideoViewController = null; await irisMethodChannel.unregisterEventHandlers(_rtcEngineImplScopedKey); diff --git a/test_shard/integration_test_app/integration_test/testcases/rtcengine_smoke_test_testcases.dart b/test_shard/integration_test_app/integration_test/testcases/rtcengine_smoke_test_testcases.dart index 1ef98cc17..bc7f1e22d 100644 --- a/test_shard/integration_test_app/integration_test/testcases/rtcengine_smoke_test_testcases.dart +++ b/test_shard/integration_test_app/integration_test/testcases/rtcengine_smoke_test_testcases.dart @@ -371,5 +371,24 @@ void testCases() { await rtcEngine.setupLocalVideo(const VideoCanvas()); }, ); + + testWidgets( + 'call release without calling initialize directly, do not thorw error', + (WidgetTester tester) async { + app.main(); + await tester.pumpAndSettle(); + + String engineAppId = const String.fromEnvironment('TEST_APP_ID', + defaultValue: ''); + + RtcEngineEx rtcEngine = createAgoraRtcEngineEx(); + await rtcEngine.release(); + + await rtcEngine.initialize(RtcEngineContext( + appId: engineAppId, + areaCode: AreaCode.areaCodeGlob.value(), + )); + }, + ); }); }