added count hook to prevent infinite lua loops from running the engine forever
git-svn-id: svn://anubis/anaglym/trunk@151 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
7e17b0f220
commit
a9ab2a2be4
19
Engine.cc
19
Engine.cc
@ -30,6 +30,8 @@ using namespace std;
|
|||||||
do { EVENT_PRESENT_FLAG(event) = false; } while(0)
|
do { EVENT_PRESENT_FLAG(event) = false; } while(0)
|
||||||
|
|
||||||
#define WHITESPACE " \t\r\n\f"
|
#define WHITESPACE " \t\r\n\f"
|
||||||
|
#define HOOK_TIMEOUT 10000u
|
||||||
|
#define HOOK_STEPS 250000000
|
||||||
|
|
||||||
#define FP_EQ(a,b) (fabsf(a - b) < 0.0001)
|
#define FP_EQ(a,b) (fabsf(a - b) < 0.0001)
|
||||||
|
|
||||||
@ -63,6 +65,11 @@ static void cross_product(dVector3 result, dVector3 first, dVector3 second)
|
|||||||
result[2] = first[0] * second[1] - first[1] * second[0];
|
result[2] = first[0] * second[1] - first[1] * second[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void debug_hook(lua_State * L, lua_Debug * debug)
|
||||||
|
{
|
||||||
|
g_engine->debug_hook(debug);
|
||||||
|
}
|
||||||
|
|
||||||
/******** Engine functions ********/
|
/******** Engine functions ********/
|
||||||
|
|
||||||
Engine::Engine(const string & path, Video & video)
|
Engine::Engine(const string & path, Video & video)
|
||||||
@ -84,6 +91,7 @@ Engine::Engine(const string & path, Video & video)
|
|||||||
m_autoEndFrame = true;
|
m_autoEndFrame = true;
|
||||||
m_autoDrawObjects = true;
|
m_autoDrawObjects = true;
|
||||||
m_fileLoader = new EngineFileLoader(this);
|
m_fileLoader = new EngineFileLoader(this);
|
||||||
|
m_event_time = 0;
|
||||||
|
|
||||||
size_t pos = path.find_last_of("\\/");
|
size_t pos = path.find_last_of("\\/");
|
||||||
m_engine_path = (pos != string::npos) ? string(path, 0, pos) : ".";
|
m_engine_path = (pos != string::npos) ? string(path, 0, pos) : ".";
|
||||||
@ -131,6 +139,7 @@ bool Engine::load(const char * program)
|
|||||||
if (s == 0)
|
if (s == 0)
|
||||||
{
|
{
|
||||||
// execute Lua program
|
// execute Lua program
|
||||||
|
lua_sethook(m_luaState, ::debug_hook, LUA_MASKCOUNT, HOOK_STEPS);
|
||||||
s = lua_pcall(m_luaState, 0, LUA_MULTRET, 0);
|
s = lua_pcall(m_luaState, 0, LUA_MULTRET, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -426,6 +435,15 @@ GLuint Engine::loadTexture(const char * name)
|
|||||||
return m_textureCache.load(path, *m_fileLoader);
|
return m_textureCache.load(path, *m_fileLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::debug_hook(lua_Debug * debug)
|
||||||
|
{
|
||||||
|
Uint32 ticks = SDL_GetTicks();
|
||||||
|
if (ticks - m_event_time > HOOK_TIMEOUT)
|
||||||
|
{
|
||||||
|
::exit(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* called by SDL when the update timer expires */
|
/* called by SDL when the update timer expires */
|
||||||
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
||||||
{
|
{
|
||||||
@ -452,6 +470,7 @@ void Engine::run()
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_WaitEvent(&event))
|
while (SDL_WaitEvent(&event))
|
||||||
{
|
{
|
||||||
|
m_event_time = SDL_GetTicks();
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
|
2
Engine.h
2
Engine.h
@ -133,6 +133,7 @@ class Engine
|
|||||||
void exit();
|
void exit();
|
||||||
bool import(const char * name);
|
bool import(const char * name);
|
||||||
GLuint loadTexture(const char * name);
|
GLuint loadTexture(const char * name);
|
||||||
|
void debug_hook(lua_Debug * debug);
|
||||||
|
|
||||||
/* lua services */
|
/* lua services */
|
||||||
int setCamera(lua_State * L);
|
int setCamera(lua_State * L);
|
||||||
@ -177,6 +178,7 @@ class Engine
|
|||||||
std::map<std::string, bool> m_keysDown;
|
std::map<std::string, bool> m_keysDown;
|
||||||
SDL_Event m_updateEvent;
|
SDL_Event m_updateEvent;
|
||||||
SDL_Event m_exitEvent;
|
SDL_Event m_exitEvent;
|
||||||
|
Uint32 m_event_time;
|
||||||
|
|
||||||
bool m_event_update_present;
|
bool m_event_update_present;
|
||||||
bool m_event_key_down_present;
|
bool m_event_key_down_present;
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
|
|
||||||
|
while (9)
|
||||||
|
do
|
||||||
|
end
|
||||||
|
|
||||||
ground = ag.createStaticPlane(0, 0, 0, 0, 0, 0)
|
ground = ag.createStaticPlane(0, 0, 0, 0, 0, 0)
|
||||||
ground:setColor(0.2, 1.0, 0.2)
|
ground:setColor(0.2, 1.0, 0.2)
|
||||||
ag.setCamera(10, -10, 10, 0, 0, 0)
|
ag.setCamera(10, -10, 10, 0, 0, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user