Skip to content

Commit

Permalink
fix #5483; LuaContextData drags in way too much junk
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Feb 18, 2017
1 parent 1545bb7 commit 94d76ac
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 21 deletions.
16 changes: 13 additions & 3 deletions rts/Lua/LuaContextData.h
Expand Up @@ -49,7 +49,7 @@ struct GLMatrixStateTracker {
return matrixData.mode;
}

int &GetDepth(unsigned int mode) {
int& GetDepth(unsigned int mode) {
switch (mode) {
case GL_MODELVIEW: return matrixData.modelView;
case GL_PROJECTION: return matrixData.projection;
Expand All @@ -63,7 +63,7 @@ struct GLMatrixStateTracker {

bool PushMatrix() {
unsigned int mode = GetMode();
int &depth = GetDepth(mode);
int& depth = GetDepth(mode);
if (!listMode && depth >= 255)
return false;
depth += 1;
Expand All @@ -72,7 +72,7 @@ struct GLMatrixStateTracker {

bool PopMatrix() {
unsigned int mode = GetMode();
int &depth = GetDepth(mode);
int& depth = GetDepth(mode);
if (listMode) {
depth -= 1;
return true;
Expand Down Expand Up @@ -165,6 +165,7 @@ struct GLMatrixStateTracker {


struct luaContextData {
public:
luaContextData()
: owner(nullptr)
, luamutex(nullptr)
Expand All @@ -184,6 +185,15 @@ struct luaContextData {
, selectTeam(CEventClient::NoAccessTeam)
, parser(nullptr) {}

void Clear() {
shaders.Clear();
textures.Clear();
fbos.Clear();
rbos.Clear();
displayLists.Clear();
}

public:
CLuaHandle* owner;
spring::recursive_mutex* luamutex;

Expand Down
33 changes: 15 additions & 18 deletions rts/Lua/LuaDisplayLists.h
Expand Up @@ -20,21 +20,20 @@ struct SMatrixStateData {

class CLuaDisplayLists {
public:
CLuaDisplayLists()
{
active.push_back(DLdata(0));
}

CLuaDisplayLists() { Clear(); }
~CLuaDisplayLists()
{
// free the display lists
for (int i = 0; i < (int)active.size(); i++) {
// NOTE:
// it is not an error to delete a list with id=0, but we might
// be called from ~LuaParser which can run in multiple threads
// and the null-list is always present (even after Clear())
for (size_t i = 1; i < active.size(); i++) {
glDeleteLists(active[i].id, 1);
}
}

void Clear()
{
void Clear() {
unused.clear();
active.clear();
active.push_back(DLdata(0));
Expand All @@ -44,27 +43,25 @@ class CLuaDisplayLists {

GLuint GetDList(unsigned int index) const
{
if (index < active.size()) {
if (index < active.size())
return active[index].id;
} else {
return 0;
}

return 0;
}

SMatrixStateData GetMatrixState(unsigned int index) const
{
if (index < active.size()) {
if (index < active.size())
return active[index].matData;
} else {
return SMatrixStateData();
}

return SMatrixStateData();
}

unsigned int NewDList(GLuint dlist, SMatrixStateData& m)
{
if (dlist == 0) {
if (dlist == 0)
return 0;
}

if (!unused.empty()) {
const unsigned int index = unused[unused.size() - 1];
active[index] = DLdata(dlist, m);
Expand Down
2 changes: 2 additions & 0 deletions rts/Lua/LuaFBOs.h
Expand Up @@ -16,6 +16,8 @@ class LuaFBOs {
LuaFBOs() { fbos.reserve(8); }
~LuaFBOs();

void Clear() { fbos.clear(); }

struct FBO {
void Init(lua_State* L);
void Free(lua_State* L);
Expand Down
4 changes: 4 additions & 0 deletions rts/Lua/LuaParser.cpp
Expand Up @@ -85,6 +85,10 @@ LuaParser::LuaParser(const string& _textChunk, const string& _accessModes, const

LuaParser::~LuaParser()
{
// prevent crashes in glDelete* calls since LuaParser
// might be constructed by multiple different threads
D.Clear();

if (L != nullptr)
LUA_CLOSE(&L);

Expand Down
2 changes: 2 additions & 0 deletions rts/Lua/LuaRBOs.h
Expand Up @@ -16,6 +16,8 @@ class LuaRBOs {
LuaRBOs() { rbos.reserve(8); }
~LuaRBOs();

void Clear() { rbos.clear(); }

static bool PushEntries(lua_State* L);

struct RBO;
Expand Down
5 changes: 5 additions & 0 deletions rts/Lua/LuaShaders.h
Expand Up @@ -19,6 +19,11 @@ class LuaShaders {
LuaShaders();
~LuaShaders();

void Clear() {
programs.clear();
unused.clear();
}

std::string errorLog;

GLuint GetProgramName(unsigned int progIdx) const;
Expand Down
6 changes: 6 additions & 0 deletions rts/Lua/LuaTextures.h
Expand Up @@ -21,6 +21,12 @@ class LuaTextures {
lastCode = 0;
}

void Clear() {
textureVec.clear();
textureMap.clear();
freeIndices.clear();
}

struct Texture {
Texture()
: name(""), id(0), fbo(0), fboDepth(0),
Expand Down

0 comments on commit 94d76ac

Please sign in to comment.