Skip to content

Commit

Permalink
Hopefully fixed the second invalid pointer detection that could often…
Browse files Browse the repository at this point in the history
… occur in the script manager.

For that, I removed an old allacrostian temp statement, fixing the check
about opening the same file multiple times.

This should permit me to disclose the bug origin in a easier way.

I also added a bit of useful log in case someone else got the issue.
  • Loading branch information
Yohann Ferreira committed Sep 22, 2012
1 parent c83e993 commit dd4769f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/engine/script/script.cpp
Expand Up @@ -65,9 +65,9 @@ bool ScriptEngine::SingletonInitialize() {


bool ScriptEngine::IsFileOpen(const std::string& filename) {
return false; // TEMP: working on resolving the issue with files being opened multiple times

if (_open_files.find(filename) != _open_files.end()) {
PRINT_WARNING << "The script file: " << filename << " was already open."
<< std::endl;
return true;
}
return false;
Expand Down
22 changes: 17 additions & 5 deletions src/engine/script/script_read.cpp
Expand Up @@ -98,14 +98,15 @@ bool ReadScriptDescriptor::OpenFile() {


void ReadScriptDescriptor::CloseFile() {
if (IsFileOpen() == false) {
IF_PRINT_WARNING(SCRIPT_DEBUG) << "could not close the file because it was not open." << std::endl;
if (!IsFileOpen()) {
PRINT_WARNING << "Could not close the file: " << _filename
<< " because it was not open." << std::endl;
return;
}

// Probably not needed. Script errors should be printed immediately.
if (IsErrorDetected()) {
IF_PRINT_WARNING(SCRIPT_DEBUG)
PRINT_WARNING
<< "the file " << _filename << " had the following error messages remaining:"
<< std::endl << _error_messages.str() << std::endl;
}
Expand Down Expand Up @@ -468,11 +469,17 @@ bool ReadScriptDescriptor::RunScriptFunction(const std::string& function_name) {

try {
ScriptCallFunction<void>(GetLuaState(), function_name.c_str());
} catch(luabind::error e) {
}
catch(const luabind::error& e) {
PRINT_ERROR << "Error while loading :" << function_name << std::endl;
ScriptManager->HandleLuaError(e);
return false;
}
catch (const luabind::cast_failed& e) {
PRINT_ERROR << "Error while loading :" << function_name << std::endl;
ScriptManager->HandleCastError(e);
}

return true;
}

Expand All @@ -486,11 +493,16 @@ bool ReadScriptDescriptor::RunScriptObject(const luabind::object& object) {

try {
ScriptCallFunction<void>(object);
} catch(luabind::error e) {
}
catch(const luabind::error& e) {
PRINT_ERROR << "Error while loading script object." << std::endl;
ScriptManager->HandleLuaError(e);
return false;
}
catch (const luabind::cast_failed& e) {
PRINT_ERROR << "Error while loading script object." << std::endl;
ScriptManager->HandleCastError(e);
}
return true;
}

Expand Down

0 comments on commit dd4769f

Please sign in to comment.