浏览代码

Fix Mantis #2234

CPlayerInterface instances were removed from CClient::playerint with
clear() and finish() was not called on each. Added multiple insurance.
Vadim Markovtsev 9 年之前
父节点
当前提交
4bcc43d3d0
共有 7 个文件被更改,包括 17 次插入11 次删除
  1. 4 0
      AI/VCAI/VCAI.cpp
  2. 1 1
      AI/VCAI/VCAI.h
  3. 2 0
      CCallback.cpp
  4. 1 1
      client/Client.cpp
  5. 1 2
      client/Client.h
  6. 7 7
      client/gui/CGuiHandler.cpp
  7. 1 0
      lib/CGameInterface.h

+ 4 - 0
AI/VCAI/VCAI.cpp

@@ -101,6 +101,7 @@ VCAI::VCAI(void)
 VCAI::~VCAI(void)
 {
 	LOG_TRACE(logAi);
+	finish();
 }
 
 void VCAI::availableCreaturesChanged(const CGDwelling *town)
@@ -2750,7 +2751,10 @@ void VCAI::recruitHero(const CGTownInstance * t, bool throwing)
 void VCAI::finish()
 {
 	if(makingTurn)
+	{
 		makingTurn->interrupt();
+		makingTurn->join();
+	}
 }
 
 void VCAI::requestActionASAP(std::function<void()> whatToDo)

+ 1 - 1
AI/VCAI/VCAI.h

@@ -159,7 +159,7 @@ public:
 	std::unique_ptr<boost::thread> makingTurn;
 
 	VCAI(void);
-	~VCAI(void);
+	virtual ~VCAI(void);
 
 	//TODO: use only smart pointers?
 	void tryRealize(Goals::Explore & g);

+ 2 - 0
CCallback.cpp

@@ -321,6 +321,8 @@ void CCallback::castSpell(const CGHeroInstance *hero, SpellID spellID, const int
 
 void CCallback::unregisterAllInterfaces()
 {
+	for (auto& pi : cl->playerint)
+		pi.second->finish();
 	cl->playerint.clear();
 	cl->battleints.clear();
 }

+ 1 - 1
client/Client.cpp

@@ -206,7 +206,7 @@ void CClient::save(const std::string & fname)
 void CClient::endGame( bool closeConnection /*= true*/ )
 {
 	//suggest interfaces to finish their stuff (AI should interrupt any bg working threads)
-	for(auto i : playerint)
+	for(auto& i : playerint)
 		i.second->finish();
 
 	// Game is ending

+ 1 - 2
client/Client.h

@@ -59,7 +59,7 @@ public:
 	static CConnection * justConnectToServer(const std::string &host = "", const std::string &port = ""); //connects to given host without taking any other actions (like setting up server)
 
 	CServerHandler(bool runServer = false);
-	~CServerHandler();
+	virtual ~CServerHandler();
 };
 
 template<typename T>
@@ -72,7 +72,6 @@ class ThreadSafeVector
 	boost::condition_variable cond;
 
 public:
-
 	void pushBack(const T &item)
 	{
 		TLock lock(mx);

+ 7 - 7
client/gui/CGuiHandler.cpp

@@ -19,7 +19,7 @@ extern boost::mutex eventsM;
 CondSh<bool> CGuiHandler::terminate_cond;
 boost::thread_specific_ptr<bool> inGuiThread;
 
-SObjectConstruction::SObjectConstruction( CIntObject *obj )
+SObjectConstruction::SObjectConstruction(CIntObject *obj)
 :myObj(obj)
 {
 	GH.createdObj.push_front(obj);
@@ -86,7 +86,7 @@ void CGuiHandler::handleElementDeActivate(CIntObject * elem, ui16 activityFlag)
 	elem->active_m &= ~activityFlag;
 }
 
-void CGuiHandler::popInt( IShowActivatable *top )
+void CGuiHandler::popInt(IShowActivatable *top)
 {
 	assert(listInt.front() == top);
 	top->deactivate();
@@ -97,7 +97,7 @@ void CGuiHandler::popInt( IShowActivatable *top )
 	totalRedraw();
 }
 
-void CGuiHandler::popIntTotally( IShowActivatable *top )
+void CGuiHandler::popIntTotally(IShowActivatable *top)
 {
 	assert(listInt.front() == top);
 	popInt(top);
@@ -105,7 +105,7 @@ void CGuiHandler::popIntTotally( IShowActivatable *top )
 	fakeMouseMove();
 }
 
-void CGuiHandler::pushInt( IShowActivatable *newInt )
+void CGuiHandler::pushInt(IShowActivatable *newInt)
 {
 	assert(newInt);
 	assert(boost::range::find(listInt, newInt) == listInt.end()); // do not add same object twice
@@ -121,7 +121,7 @@ void CGuiHandler::pushInt( IShowActivatable *newInt )
 	totalRedraw();
 }
 
-void CGuiHandler::popInts( int howMany )
+void CGuiHandler::popInts(int howMany)
 {
 	if(!howMany) return; //senseless but who knows...
 
@@ -364,7 +364,7 @@ void CGuiHandler::simpleRedraw()
 	objsToBlit.back()->show(screen); //blit active interface/window
 }
 
-void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion )
+void CGuiHandler::handleMoveInterested(const SDL_MouseMotionEvent & motion)
 {
 	//sending active, MotionInterested objects mouseMoved() call
 	std::list<CIntObject*> miCopy = motioninterested;
@@ -463,7 +463,7 @@ void CGuiHandler::drawFPSCounter()
 	graphics->fonts[FONT_BIG]->renderTextLeft(screen, fps, yellow, Point(10, 10));
 }
 
-SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key )
+SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key)
 {
 	switch(key)
 	{

+ 1 - 0
lib/CGameInterface.h

@@ -82,6 +82,7 @@ public:
 class DLL_LINKAGE CGameInterface : public CBattleGameInterface, public IGameEventsReceiver
 {
 public:
+	virtual ~CGameInterface() = default;
 	virtual void init(std::shared_ptr<CCallback> CB){};
 	virtual void yourTurn(){}; //called AFTER playerStartsTurn(player)