diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-18 23:17:31 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-01-19 23:22:44 +0100 |
commit | db8df518c05d38c3d7452fe8f18fdc7c48c3eb4e (patch) | |
tree | 33e9a2b1bc899dbcd47ea26804daaebde0a9fe48 /src/net/tmwa/gamehandler.cpp | |
parent | 7272d727271b226948ff56f486a3f322fe1762bd (diff) | |
download | mana-db8df518c05d38c3d7452fe8f18fdc7c48c3eb4e.tar.gz mana-db8df518c05d38c3d7452fe8f18fdc7c48c3eb4e.tar.bz2 mana-db8df518c05d38c3d7452fe8f18fdc7c48c3eb4e.tar.xz mana-db8df518c05d38c3d7452fe8f18fdc7c48c3eb4e.zip |
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
Diffstat (limited to 'src/net/tmwa/gamehandler.cpp')
-rw-r--r-- | src/net/tmwa/gamehandler.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
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) |