From 5b919d88eb4a1f93ac8c4b0ce0d34ed2972f152f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sun, 20 Jan 2013 12:06:49 +0000 Subject: [PATCH] "More stable" opening AI. --- AI/BattleAI/BattleAI.cpp | 9 ++++++--- client/CMT.cpp | 18 +++++++++++------- lib/CGameInterface.cpp | 6 ++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/AI/BattleAI/BattleAI.cpp b/AI/BattleAI/BattleAI.cpp index 4b7ff0ff5..25cba4e5f 100644 --- a/AI/BattleAI/BattleAI.cpp +++ b/AI/BattleAI/BattleAI.cpp @@ -71,9 +71,12 @@ CBattleAI::~CBattleAI(void) { print("destroyed"); - //Restore previous state of CB - it may be shared with the main AI (like VCAI) - cb->waitTillRealize = wasWaitingForRealize; - cb->unlockGsWhenWaiting = wasUnlockingGs; + if(cb) + { + //Restore previous state of CB - it may be shared with the main AI (like VCAI) + cb->waitTillRealize = wasWaitingForRealize; + cb->unlockGsWhenWaiting = wasUnlockingGs; + } } void CBattleAI::init( CBattleCallback * CB ) diff --git a/client/CMT.cpp b/client/CMT.cpp index ebdc540b8..24cb2ad09 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -616,16 +616,20 @@ void processCommand(const std::string &message) std::string fname; readed >> fname; tlog0 << "Will try loading that AI to see if it is correct name...\n"; - if(auto ai = CDynLibHandler::getNewBattleAI(fname)) //test that given AI is indeed available... heavy but it is easy to make a typo and break the game + try { - delete ai; - Settings neutralAI = settings.write["server"]["neutralAI"]; - neutralAI->String() = fname; - tlog0 << "Setting changed, from now the battle ai will be " << fname << "!\n"; + if(auto ai = CDynLibHandler::getNewBattleAI(fname)) //test that given AI is indeed available... heavy but it is easy to make a typo and break the game + { + delete ai; + Settings neutralAI = settings.write["server"]["neutralAI"]; + neutralAI->String() = fname; + tlog0 << "Setting changed, from now the battle ai will be " << fname << "!\n"; + } } - else + catch(std::exception &e) { - tlog3 << "Setting not changes, no such AI found!\n"; + tlog3 << "Failed opening " << fname << ": " << e.what() << std::endl; + tlog3 << "Setting not changes, AI not found or invalid!\n"; } } else if(client && client->serv && client->serv->connected && LOCPLINT) //send to server diff --git a/lib/CGameInterface.cpp b/lib/CGameInterface.cpp index 04e94cefd..d9d0e978d 100644 --- a/lib/CGameInterface.cpp +++ b/lib/CGameInterface.cpp @@ -51,6 +51,12 @@ rett * createAny(std::string dllname, std::string methodName) tlog1 << "Cannot open dynamic library ("<