1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

Fix adventure map movement segfault in some scenarios

This commit is contained in:
Vadim Markovtsev
2015-10-31 20:23:13 +03:00
parent fa8a282696
commit e6e975e9ef
3 changed files with 24 additions and 23 deletions

View File

@ -62,9 +62,9 @@ CAdvMapInt *adventureInt;
CTerrainRect::CTerrainRect() CTerrainRect::CTerrainRect()
: fadeSurface(nullptr), : fadeSurface(nullptr),
fadeAnim(new CFadeAnimation()), fadeAnim(new CFadeAnimation()),
curHoveredTile(-1,-1,-1), curHoveredTile(-1,-1,-1),
currentPath(nullptr) currentPath(nullptr)
{ {
tilesw=(ADVOPT.advmapW+31)/32; tilesw=(ADVOPT.advmapW+31)/32;
@ -283,7 +283,7 @@ void CTerrainRect::show(SDL_Surface * to)
info.heroAnim = adventureInt->heroAnim; info.heroAnim = adventureInt->heroAnim;
if (ADVOPT.smoothMove) if (ADVOPT.smoothMove)
info.movement = int3(moveX, moveY, 0); info.movement = int3(moveX, moveY, 0);
lastRedrawStatus = CGI->mh->drawTerrainRectNew(to, &info); lastRedrawStatus = CGI->mh->drawTerrainRectNew(to, &info);
if (fadeAnim->isFading()) if (fadeAnim->isFading())
{ {
@ -316,7 +316,7 @@ void CTerrainRect::showAll(SDL_Surface * to)
} }
void CTerrainRect::showAnim(SDL_Surface * to) void CTerrainRect::showAnim(SDL_Surface * to)
{ {
if (fadeAnim->isFading()) if (fadeAnim->isFading())
show(to); show(to);
else if (lastRedrawStatus == EMapAnimRedrawStatus::REDRAW_REQUESTED) else if (lastRedrawStatus == EMapAnimRedrawStatus::REDRAW_REQUESTED)
@ -357,7 +357,7 @@ void CTerrainRect::fadeFromCurrentView()
return; return;
if (adventureInt->mode == EAdvMapMode::WORLD_VIEW) if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
return; return;
if (!fadeSurface) if (!fadeSurface)
fadeSurface = CSDL_Ext::newSurface(pos.w, pos.h); fadeSurface = CSDL_Ext::newSurface(pos.w, pos.h);
SDL_BlitSurface(screen, &pos, fadeSurface, nullptr); SDL_BlitSurface(screen, &pos, fadeSurface, nullptr);
@ -502,10 +502,10 @@ CAdvMapInt::CAdvMapInt():
endTurn = makeButton(302, std::bind(&CAdvMapInt::fendTurn,this), ADVOPT.endTurn, SDLK_e); endTurn = makeButton(302, std::bind(&CAdvMapInt::fendTurn,this), ADVOPT.endTurn, SDLK_e);
int panelSpaceBottom = screen->h - resdatabar.pos.h - 4; int panelSpaceBottom = screen->h - resdatabar.pos.h - 4;
panelMain = new CAdvMapPanel(nullptr, Point(0, 0)); panelMain = new CAdvMapPanel(nullptr, Point(0, 0));
// TODO correct drawing position // TODO correct drawing position
panelWorldView = new CAdvMapWorldViewPanel(bgWorldView, Point(heroList.pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID); panelWorldView = new CAdvMapWorldViewPanel(bgWorldView, Point(heroList.pos.x - 2, 195), panelSpaceBottom, LOCPLINT->playerID);
panelMain->addChildColorableButton(kingOverview); panelMain->addChildColorableButton(kingOverview);
panelMain->addChildColorableButton(underground); panelMain->addChildColorableButton(underground);
@ -593,7 +593,7 @@ CAdvMapInt::CAdvMapInt():
Colors::WHITE, CGI->generaltexth->allTexts[618])); Colors::WHITE, CGI->generaltexth->allTexts[618]));
activeMapPanel = panelMain; activeMapPanel = panelMain;
changeMode(EAdvMapMode::NORMAL); changeMode(EAdvMapMode::NORMAL);
underground->block(!CGI->mh->map->twoLevel); underground->block(!CGI->mh->map->twoLevel);
@ -966,7 +966,7 @@ void CAdvMapInt::show(SDL_Surface * to)
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
blitAt(gems[i]->ourImages[LOCPLINT->playerID.getNum()].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to); blitAt(gems[i]->ourImages[LOCPLINT->playerID.getNum()].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i],to);
} }
infoBar.show(to); infoBar.show(to);
statusbar.showAll(to); statusbar.showAll(to);
} }
@ -981,7 +981,7 @@ void CAdvMapInt::selectionChanged()
void CAdvMapInt::centerOn(int3 on, bool fade /* = false */) void CAdvMapInt::centerOn(int3 on, bool fade /* = false */)
{ {
bool switchedLevels = on.z != position.z; bool switchedLevels = on.z != position.z;
if (fade) if (fade)
{ {
terrain.fadeFromCurrentView(); terrain.fadeFromCurrentView();
@ -1534,7 +1534,9 @@ void CAdvMapInt::tileHovered(const int3 &mapPos)
} }
else if(const CGHeroInstance *h = curHero()) else if(const CGHeroInstance *h = curHero())
{ {
const CGPathNode *pnode = LOCPLINT->cb->getPathsInfo(h)->getPathInfo(mapPos); int3 mapPosCopy = mapPos;
const CGPathNode *pnode = LOCPLINT->cb->getPathsInfo(h)->getPathInfo(mapPosCopy);
assert(pnode);
int turns = pnode->turns; int turns = pnode->turns;
vstd::amin(turns, 3); vstd::amin(turns, 3);
@ -1780,9 +1782,9 @@ void CAdvMapInt::changeMode(EAdvMapMode newMode, float newScale /* = 0.4f */)
townList.activate(); townList.activate();
heroList.activate(); heroList.activate();
infoBar.activate(); infoBar.activate();
worldViewOptions.clear(); worldViewOptions.clear();
break; break;
case EAdvMapMode::WORLD_VIEW: case EAdvMapMode::WORLD_VIEW:
panelMain->deactivate(); panelMain->deactivate();
@ -1852,14 +1854,13 @@ CAdvMapInt::WorldViewOptions::WorldViewOptions()
void CAdvMapInt::WorldViewOptions::clear() void CAdvMapInt::WorldViewOptions::clear()
{ {
showAllTerrain = false; showAllTerrain = false;
iconPositions.clear(); iconPositions.clear();
} }
void CAdvMapInt::WorldViewOptions::adjustDrawingInfo(MapDrawingInfo& info) void CAdvMapInt::WorldViewOptions::adjustDrawingInfo(MapDrawingInfo& info)
{ {
info.showAllTerrain = showAllTerrain; info.showAllTerrain = showAllTerrain;
info.additionalIcons = &iconPositions;
}
info.additionalIcons = &iconPositions;
}

View File

@ -674,8 +674,8 @@ void CGameState::randomizeObject(CGObjectInstance *cur)
} }
else else
{ {
cur->setType(ran.first, ran.second); cur->setType(ran.first, ran.second);
} }
} }
int CGameState::getDate(Date::EDateType mode) const int CGameState::getDate(Date::EDateType mode) const
@ -2899,11 +2899,11 @@ bool CGPathNode::reachable() const
return turns < 255; return turns < 255;
} }
const CGPathNode * CPathsInfo::getPathInfo( int3 tile ) const const CGPathNode * CPathsInfo::getPathInfo( const int3& tile ) const
{ {
boost::unique_lock<boost::mutex> pathLock(pathMx); boost::unique_lock<boost::mutex> pathLock(pathMx);
if (tile.x >= sizes.x || tile.y >= sizes.y || tile.z >= sizes.z ||
if (tile.x >= sizes.x || tile.y >= sizes.y || tile.z >= sizes.z) tile.x < 0 || tile.y < 0 || tile.z < 0)
return nullptr; return nullptr;
return &nodes[tile.x][tile.y][tile.z]; return &nodes[tile.x][tile.y][tile.z];
} }

View File

@ -158,7 +158,7 @@ struct DLL_LINKAGE CPathsInfo
int3 sizes; int3 sizes;
CGPathNode ***nodes; //[w][h][level] CGPathNode ***nodes; //[w][h][level]
const CGPathNode * getPathInfo( int3 tile ) const; const CGPathNode * getPathInfo( const int3& tile ) const;
bool getPath(const int3 &dst, CGPath &out) const; bool getPath(const int3 &dst, CGPath &out) const;
int getDistance( int3 tile ) const; int getDistance( int3 tile ) const;
CPathsInfo(const int3 &Sizes); CPathsInfo(const int3 &Sizes);