Skip to content
Snippets Groups Projects
Commit 82179945 authored by DarkGod's avatar DarkGod
Browse files

Fixed crash after saving that happened to some people

parent 50afacc9
No related branches found
No related tags found
No related merge requests found
......@@ -82,6 +82,8 @@ newTalent{
if self:canMove(x, y) then
self:move(x, y)
moved = 1
else
self:useEnergy(game.energy_to_act)
end
local fx, fy = util.coordAddDir(self.x, self.y, dir)
......
......@@ -33,7 +33,7 @@ return {
-- [[
class = "engine.generator.map.Empty",
up = "FLOOR",
floor = "TREE",
floor = "FLOOR",
--]]
--[[
class = "engine.generator.map.Building",
......
......@@ -99,6 +99,7 @@ static int map_object_new(lua_State *L)
obj->dh = luaL_checknumber(L, 9);
obj->scale = luaL_checknumber(L, 10);
obj->shader = NULL;
obj->shader_ref = LUA_NOREF;
obj->tint_r = obj->tint_g = obj->tint_b = 1;
for (i = 0; i < nb_textures; i++)
{
......@@ -117,9 +118,10 @@ static int map_object_free(lua_State *L)
map_object *obj = (map_object*)auxiliar_checkclass(L, "core{mapobj}", 1);
int i;
for (i = 0; i < obj->nb_textures; i++)
for (i = 0; i < obj->nb_textures; i++) {
if (obj->textures_ref[i] != LUA_NOREF)
luaL_unref(L, LUA_REGISTRYINDEX, obj->textures_ref[i]);
}
free(obj->textures);
free(obj->tex_x);
......@@ -141,6 +143,11 @@ static int map_object_free(lua_State *L)
obj->cb_ref = LUA_NOREF;
}
if (obj->shader_ref != LUA_NOREF) {
luaL_unref(L, LUA_REGISTRYINDEX, obj->shader_ref);
obj->shader_ref = LUA_NOREF;
}
lua_pushnumber(L, 1);
return 1;
}
......@@ -212,7 +219,11 @@ static int map_object_shader(lua_State *L)
if (!lua_isnil(L, 2)) {
shader_type *s = (shader_type*)lua_touserdata(L, 2);
obj->shader = s;
lua_pushvalue(L, 2);
obj->shader_ref = luaL_ref(L, LUA_REGISTRYINDEX);
} else {
luaL_unref(L, LUA_REGISTRYINDEX, obj->shader_ref);
obj->shader_ref = LUA_NOREF;
obj->shader = NULL;
}
return 0;
......
......@@ -31,6 +31,7 @@ struct s_map_object {
GLfloat *tex_x, *tex_y, *tex_factorx, *tex_factory;
bool *textures_is3d;
shader_type *shader;
int shader_ref;
int cur_x, cur_y;
float dx, dy, scale;
float animdx, animdy;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment