Skip to content

Commit

Permalink
[unity]~GenericDelegate时,如果jsenv已经被dispose,不用抛异常,fix #1677
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Mar 21, 2024
1 parent 02c13cf commit 6b1b257
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,13 @@ private void CheckLiveness(bool shouldThrow = true)
~GenericDelegate()
{
if (nativeJsFuncPtr == IntPtr.Zero) return;
CheckLiveness(false);
#if THREAD_SAFE
lock(jsEnv) {
#endif
jsEnv.DecFuncRef(nativeJsFuncPtr);
if (jsEnv.CheckLiveness(false))
{
jsEnv.DecFuncRef(nativeJsFuncPtr);
}
#if THREAD_SAFE
}
#endif
Expand Down
5 changes: 3 additions & 2 deletions unity/Assets/core/upm/Runtime/Src/Default/JsEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,13 @@ protected virtual void Dispose(bool dispose)
}
}

internal void CheckLiveness()
internal bool CheckLiveness(bool shouldThrow = true)
{
if (disposed)
if (disposed && shouldThrow)
{
throw new InvalidOperationException("JsEnv has been disposed!");
}
return !disposed;
}

Dictionary<IntPtr, int> funcRefCount = new Dictionary<IntPtr, int>();
Expand Down
4 changes: 2 additions & 2 deletions unity/test/Src/Cases/AccessControlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public AccessControlTest()
[OneTimeTearDown]
public void Cleanup()
{
GC.Collect();
GC.WaitForPendingFinalizers();
//GC.Collect();
//GC.WaitForPendingFinalizers();
DefaultDontBindingEnv.Dispose();
}
#endif
Expand Down

0 comments on commit 6b1b257

Please sign in to comment.