Browse Source

Avoid crashes caused by mouse events. Fix issue 1955

Mouse handling code need refactoring, but for now we at least shouldn't crash.
Arseniy Shestakov 9 years ago
parent
commit
46e3d849af
2 changed files with 8 additions and 5 deletions
  1. 7 4
      client/windows/CAdvmapInterface.cpp
  2. 1 1
      client/windows/CAdvmapInterface.h

+ 7 - 4
client/windows/CAdvmapInterface.cpp

@@ -322,18 +322,21 @@ void CTerrainRect::showAnim(SDL_Surface * to)
 		show(to); // currently the same; maybe we should pass some flag to map handler so it redraws ONLY tiles that need redraw instead of full
 		show(to); // currently the same; maybe we should pass some flag to map handler so it redraws ONLY tiles that need redraw instead of full
 }
 }
 
 
-int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)
+int3 CTerrainRect::whichTileIsIt(const int x, const int y)
 {
 {
 	int3 ret;
 	int3 ret;
-	ret.x = adventureInt->position.x + ((GH.current->motion.x-CGI->mh->offsetX-pos.x)/32);
-	ret.y = adventureInt->position.y + ((GH.current->motion.y-CGI->mh->offsetY-pos.y)/32);
+	ret.x = adventureInt->position.x + ((x-CGI->mh->offsetX-pos.x)/32);
+	ret.y = adventureInt->position.y + ((y-CGI->mh->offsetY-pos.y)/32);
 	ret.z = adventureInt->position.z;
 	ret.z = adventureInt->position.z;
 	return ret;
 	return ret;
 }
 }
 
 
 int3 CTerrainRect::whichTileIsIt()
 int3 CTerrainRect::whichTileIsIt()
 {
 {
-	return whichTileIsIt(GH.current->motion.x,GH.current->motion.y);
+	if(GH.current)
+		return whichTileIsIt(GH.current->motion.x,GH.current->motion.y);
+	else
+		return int3(-1);
 }
 }
 
 
 int3 CTerrainRect::tileCountOnScreen()
 int3 CTerrainRect::tileCountOnScreen()

+ 1 - 1
client/windows/CAdvmapInterface.h

@@ -74,7 +74,7 @@ public:
 	void showAll(SDL_Surface * to) override;
 	void showAll(SDL_Surface * to) override;
 	void showAnim(SDL_Surface * to);
 	void showAnim(SDL_Surface * to);
 	void showPath(const SDL_Rect * extRect, SDL_Surface * to);
 	void showPath(const SDL_Rect * extRect, SDL_Surface * to);
-	int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
+	int3 whichTileIsIt(const int x, const int y); //x,y are cursor position
 	int3 whichTileIsIt(); //uses current cursor pos
 	int3 whichTileIsIt(); //uses current cursor pos
 	/// @returns number of visible tiles on screen respecting current map scaling
 	/// @returns number of visible tiles on screen respecting current map scaling
 	int3 tileCountOnScreen();
 	int3 tileCountOnScreen();