-
Notifications
You must be signed in to change notification settings - Fork 40
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
Lua program crashes when using delegates instead of function pointers #87
Comments
Anonymous functions and (non-static) nested functions should behave exactly the same - they are both delegates, and they both produce closures when that delegate is escaped. Maybe your second example isn't true to exactly what they tried when it worked? Anyway, LuaD should be handling the GC problem by calling However, I'm not 100% sure how the conservative D GC handles manually added roots and ranges. Maybe it should be Maybe some other issue is at play? |
This is the fixed version: class Game3D : RenderLayer
{
private LuaTable playerTable;
private Player player;
... // Player initialization, Asset loading etc
private int getX() { return player.x; }
... // More functions
public void setLua(LuaState lua)
{
playerTable = lua.newTable();
playerTable["getX"] = &getX;
auto plugins = dirEntries("plugins/", SpanMode.shallow, false);
foreach(string file; plugins)
{
if(file.endsWith(".lua"))
{
try
{
lua.doFile(file); // file containing my code
}
catch(LuaErrorException e)
{
Logger.errln(e);
}
Logger.writeln("Loaded plugin from ", file);
}
}
}
} |
Indeed, (non-static) member functions have a different delegate context. I think maybe the fix would be to change edit: And corresponding change in GC.removeRoot(lua_touserdata(L, 1));
->
GC.removeRange(lua_touserdata(L, 1)); |
I didnt try with a clean app but with my engine it crashes (only for other people, I couldn't reproduce it) when i use
When I use derp frequently by calling the lua function which calls derp it will eventually crash after some undefined time. However when I create a function for that and then reference that, it will never crash. Maybe its something with the D garbage collector deleting the lambdas because it thinks it isnt used. So this works:
The text was updated successfully, but these errors were encountered: