From db8df518c05d38c3d7452fe8f18fdc7c48c3eb4e Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 18 Jan 2012 23:17:31 +0100 Subject: Fixed handling of problems with loading the initial map This can always happen, either due to mismatching local data or a server-side error. The client displays a pop-up in this case, but it's not possible to read that when it crashes as well. Reviewed-by: Yohann Ferreira --- src/net/tmwa/gamehandler.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index 9e2c6fa4..5719f700 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -108,14 +108,15 @@ void GameHandler::event(Event::Channel channel, const Event &event) { Game *game = Game::instance(); game->changeMap(mMap); - Map *map = game->getCurrentMap(); - const int tileWidth = map->getTileWidth(); - const int tileHeight = map->getTileHeight(); - if (mTileX && mTileY) + + // It could be that loading the map failed + if (Map *map = game->getCurrentMap()) { - local_player->setPosition(Vector(mTileX * tileWidth + tileWidth / 2, - mTileY * tileHeight + tileHeight / 2)); - mTileX = mTileY = 0; + if (mTileX && mTileY) + { + local_player->setPosition(map->getTileCenter(mTileX, mTileY)); + mTileX = mTileY = 0; + } } } else if (event.getType() == Event::MapLoaded) -- cgit v1.2.3-70-g09d2