Browse files

Catched another script file open without its counter closeFile call.

This will help fix issue #15

I also added the try/catch useful to get feedback for bugs in lua
scripts.
  • Loading branch information...
1 parent bf07602 commit 4e895d15ded901c3e603a5b011d40798c62392a8 Yohann Ferreira committed Nov 8, 2012
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/modes/map/map_sprites.cpp
View
16 src/modes/map/map_sprites.cpp
@@ -1091,7 +1091,6 @@ EnemySprite::EnemySprite() :
_time_dir_change(2500),
_time_to_spawn(STANDARD_ENEMY_FIRST_SPAWN_TIME)
{
- _filename = "";
MapObject::_object_type = ENEMY_TYPE;
moving = true;
Reset();
@@ -1120,7 +1119,20 @@ bool EnemySprite::Load()
if(!sprite_script.OpenFile(_filename))
return false;
- ScriptCallFunction<void>(sprite_script.GetLuaState(), "Load", this);
+ try {
+ ScriptCallFunction<void>(sprite_script.GetLuaState(), "Load", this);
+ } catch(const luabind::error &e) {
+ PRINT_ERROR << "Error while loading Load() function from:"
+ << sprite_script.GetFilename() << std::endl;
+ ScriptManager->HandleLuaError(e);
+ return false;
+ } catch(const luabind::cast_failed &e) {
+ PRINT_ERROR << "Error while loading Load() function from:"
+ << sprite_script.GetFilename() << std::endl;
+ ScriptManager->HandleCastError(e);
+ }
+
+ sprite_script.CloseFile();
return true;
}

0 comments on commit 4e895d1

Please sign in to comment.