mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Changed luax_pushtype to retain the pushed object itself, but only if the object isn't in the Lua state already.
Previously, calling e.g. love.graphics.getFont() 10,000 times would retain the object 10,000 times (and release it 10,000 times when the Font object was garbage-collected in the Lua state.) Now it will only retain it once and release it once.
This commit is contained in:
@@ -263,18 +263,13 @@ int w_Mesh_getTexture(lua_State *L)
|
||||
if (tex == nullptr)
|
||||
return 0;
|
||||
|
||||
tex->retain();
|
||||
|
||||
// FIXME: big hack right here.
|
||||
if (typeid(*tex) == typeid(Image))
|
||||
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, tex);
|
||||
else if (typeid(*tex) == typeid(Canvas))
|
||||
luax_pushtype(L, "Canvas", GRAPHICS_CANVAS_T, tex);
|
||||
else
|
||||
{
|
||||
tex->release();
|
||||
return luaL_error(L, "Unable to determine texture type.");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user