Tencent/puerts

[Unity]GenericDelegate析构检查到jsenv被dispose,无需抛异常

Closed this issue · 0 comments

detail | 详细描述

首先(新版)nunit要求在OneTimeTearDown方法中对JsEnv变量Dispose
https://github.com/Tencent/puerts/actions/runs/8358232240/job/22879060265

Error: /Users/runner/work/puerts/puerts/unity/test/Src/Cases/AccessControlTest.cs(39,23): error NUnit1032: The field DefaultDontBindingEnv should be Disposed in a method annotated with [OneTimeTearDownAttribute] 

加上后,会报如下错误:
https://github.com/Tencent/puerts/actions/runs/8368563099/job/22912863909

The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.InvalidOperationException: JsEnv has been disposed!
   at Puerts.JsEnv.CheckLiveness() in D:\a\puerts\puerts\unity\Assets\core\upm\Runtime\Src\Default\JsEnv.cs:line 829
   at Puerts.GenericDelegate.CheckLiveness(Boolean shouldThrow) in D:\a\puerts\puerts\unity\Assets\core\upm\Runtime\Src\Default\JSType\GenericDelegate.cs:line 362
   at Puerts.GenericDelegate.Finalize() in D:\a\puerts\puerts\unity\Assets\core\upm\Runtime\Src\Default\JSType\GenericDelegate.cs:line 369

Dispose前加上强制gc问题解决

public void Cleanup()
 {
          GC.Collect();
          GC.WaitForPendingFinalizers();
          DefaultDontBindingEnv.Dispose();
 }

不过感觉GenericDelegate的析构检查到jsenv被dispose,不必抛异常,由于gc的不可控GenericDelegate的释放可能比较后,属于正常现象。