Skip to content

Commit

Permalink
Fixed: Crash after catching an exception
Browse files Browse the repository at this point in the history
The libdeng2 exceptions have a QString as an instance variable. Never
catch exceptions by value in this case; the implicit QString memory
sharing seems to lead to malloc/free errors otherwise.
  • Loading branch information
skyjake committed Oct 16, 2012
1 parent 8967807 commit 93243ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions doomsday/engine/portable/src/dd_games.cpp
Expand Up @@ -169,7 +169,8 @@ Game& GameCollection::byIdentityKey(char const* identityKey) const
return *game;
}
}
throw NotFoundError("GameCollection::byIdentityKey", QString("There is no Game with identity key \"%s\"").arg(identityKey));
throw NotFoundError("GameCollection::byIdentityKey",
QString("There is no Game with identity key \"%1\"").arg(identityKey));
}

Game& GameCollection::byIndex(int idx) const
Expand Down Expand Up @@ -446,7 +447,7 @@ Game* GameCollection_ByIndex(GameCollection* games, int idx)
{
return reinterpret_cast<Game*>(&self->byIndex(idx));
}
catch(de::GameCollection::NotFoundError)
catch(const de::GameCollection::NotFoundError&)
{} // Ignore error.
return 0; // Not found.
}
Expand All @@ -458,7 +459,7 @@ Game* GameCollection_ByIdentityKey(GameCollection* games, char const* identityKe
{
return reinterpret_cast<Game*>(&self->byIdentityKey(identityKey));
}
catch(de::GameCollection::NotFoundError)
catch(const de::GameCollection::NotFoundError&)
{} // Ignore error.
return 0; // Not found.
}
Expand All @@ -470,7 +471,7 @@ gameid_t GameCollection_Id(GameCollection* games, Game* game)
{
return self->id(*reinterpret_cast<de::Game*>(game));
}
catch(de::GameCollection::NotFoundError)
catch(const de::GameCollection::NotFoundError&)
{} // Ignore error.
return 0; // Invalid id.
}
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/src/dd_main.cpp
Expand Up @@ -777,7 +777,7 @@ gameid_t DD_DefineGame(GameDef const* def)
#endif
return 0; // Invalid id.
}
catch(de::GameCollection::NotFoundError)
catch(const de::GameCollection::NotFoundError&)
{} // Ignore the error.

de::Game* game = de::Game::fromDef(*def);
Expand All @@ -797,7 +797,7 @@ gameid_t DD_GameIdForKey(const char* identityKey)
{
return games->id(games->byIdentityKey(identityKey));
}
catch(de::GameCollection::NotFoundError)
catch(const de::GameCollection::NotFoundError&)
{
DEBUG_Message(("Warning: DD_GameIdForKey: Game \"%s\" not defined.\n", identityKey));
}
Expand Down Expand Up @@ -1073,7 +1073,7 @@ de::Game* DD_AutoselectGame(void)
return &game;
}
}
catch(de::GameCollection::NotFoundError)
catch(const de::GameCollection::NotFoundError&)
{} // Ignore the error.
}

Expand Down Expand Up @@ -2148,7 +2148,7 @@ D_CMD(Load)
didLoadGame = true;
++arg;
}
catch(de::GameCollection::NotFoundError)
catch(const de::GameCollection::NotFoundError&)
{} // Ignore the error.

// Try the resource locator.
Expand Down Expand Up @@ -2223,7 +2223,7 @@ D_CMD(Unload)
Con_Message("%s is not currently loaded.\n", Str_Text(&game.identityKey()));
return true;
}
catch(de::GameCollection::NotFoundError)
catch(const de::GameCollection::NotFoundError&)
{} // Ignore the error.
}

Expand Down

0 comments on commit 93243ca

Please sign in to comment.