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

Xlua中Dispose()释放报错委托回调问题 #1150

Open
27657237 opened this issue Jul 18, 2024 · 1 comment
Open

Xlua中Dispose()释放报错委托回调问题 #1150

27657237 opened this issue Jul 18, 2024 · 1 comment

Comments

@27657237
Copy link

27657237 commented Jul 18, 2024

public delegate void LuaFunction_();
[GCOptimize]
public struct LuaBootstrap
{
public LuaFunction_ Start;
public LuaFunction_ Update;
public LuaFunction_ OnDestroy;
}

public class Bootstrap : MonoBehaviour
{
private LuaBootstrap bootstrap;

void Start()
{
    XluaEnv.Instance.DoString("require('Bootstrap')");
    bootstrap= XluaEnv.Instance.Global.Get<LuaBootstrap>("Bootstrap");
    bootstrap.Start();
}
private void OnDestroy()
{
    bootstrap.OnDestroy();
   
    bootstrap.Start = null;
    bootstrap.Update = null;
    bootstrap.OnDestroy = null;
   
    // 最后释放 LuaEnv
    XluaEnv.Instance.Free();
}  

上面是一个简单的生命周期代码
我不知道为什么,我如果在OnDestroy方法执行一次bootstrap.OnDestroy();哪怕后续将他设置为null,在回收还会报错
(上面执行 bootstrap其他委托在设置null还是会报错,Free()方法是单例类里的释放xluaenv方法,无其他逻辑)

报错内容为:
InvalidOperationException: try to dispose a LuaEnv with C# callback!
XLua.LuaEnv.Dispose (System.Boolean dispose) (at Assets/ThirdParty/XLua/Src/LuaEnv.cs:424)
XLua.LuaEnv.Dispose () (at Assets/ThirdParty/XLua/Src/LuaEnv.cs:393)
XluaEnv.Free () (at Assets/Script/Tool/XluaEnv.cs:39)
Bootstrap.OnDestroy () (at Assets/Script/Bootstrap.cs:40)

Lua源码:
Bootstrap={}
function Bootstrap.Start()
print("Lua:Start")
end
function Bootstrap.Update()
print("Lua:Update")
end
function Bootstrap.OnDestroy()
print("Lua:OnDestroy")
end

@27657237
Copy link
Author

请大佬帮我解惑,这个代码是我跟一个很老的教程学习的xlua使用方法,我并不知道这个使用方法目前是否已经过时

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

1 participant