File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
Laylua.Tests/Tests/Library/Entities Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -69,4 +69,18 @@ public void MainThreadReference_PushedToChildThreadStack_PushesReferenceToChildT
6969 Assert . That ( Lua . Stack . Count , Is . Zero ) ;
7070 Assert . That ( thread . Stack . Count , Is . EqualTo ( 1 ) ) ;
7171 }
72+
73+ [ Test ]
74+ public void MainThreadReference_MainThreadDisposed_InvalidatesReference ( )
75+ {
76+ // Arrange
77+ var lua1 = CreateLua ( ) ;
78+ var reference = lua1 . Evaluate < LuaTable > ( "return {}" ) ! ;
79+
80+ // Act
81+ lua1 . Dispose ( ) ;
82+
83+ // Assert
84+ Assert . That ( ( ) => reference . IsEmpty , Throws . TypeOf < ObjectDisposedException > ( ) . With . Property ( nameof ( ObjectDisposedException . ObjectName ) ) . EqualTo ( typeof ( LuaTable ) . FullName ) ) ;
85+ }
7286}
Original file line number Diff line number Diff line change @@ -36,7 +36,14 @@ internal int Reference
3636
3737 internal virtual bool IsDisposed
3838 {
39- get => _reference == LUA_NOREF ;
39+ get
40+ {
41+ if ( _reference is LUA_NOREF )
42+ return true ;
43+
44+ var thread = ThreadCore ;
45+ return thread == null || thread . MainThread . IsDisposed ;
46+ }
4047 set => _reference = value ? LUA_NOREF : LUA_REFNIL ;
4148 }
4249
@@ -58,7 +65,7 @@ private protected LuaReference()
5865 Lua . FromThread ( thread ) . PushLeakedReference ( _reference ) ;
5966 }
6067
61- if ( Thread ! . Marshaler . ReturnReference ( this ) )
68+ if ( thread . Marshaler . ReturnReference ( this ) )
6269 {
6370 GC . ReRegisterForFinalize ( this ) ;
6471 }
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ internal sealed class LuaMainThread : LuaThread
1111
1212 internal override LuaMarshaler Marshaler => _lua . Marshaler ;
1313
14+ internal override bool IsDisposed => _lua . IsDisposed ;
15+
1416 private readonly Lua _lua ;
1517
1618 public LuaMainThread ( Lua lua )
You can’t perform that action at this time.
0 commit comments