Skip to content

Commit

Permalink
Merge pull request #4532 from TrenchBroom/4531
Browse files Browse the repository at this point in the history
4531: Don't crash when parsing entity definition file fails
  • Loading branch information
kduske committed Mar 20, 2024
2 parents 652d0a2 + ee53792 commit d2d8fc2
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions common/src/Model/GameImpl.cpp
Expand Up @@ -415,32 +415,39 @@ Result<std::vector<std::unique_ptr<Assets::EntityDefinition>>> GameImpl::
const auto extension = path.extension().string();
const auto& defaultColor = m_config.entityConfig.defaultColor;

if (kdl::ci::str_is_equal(".fgd", extension))
{
return IO::Disk::openFile(path).transform([&](auto file) {
auto reader = file->reader().buffer();
auto parser = IO::FgdParser{reader.stringView(), defaultColor, path};
return parser.parseDefinitions(status);
});
}
if (kdl::ci::str_is_equal(".def", extension))
try
{
return IO::Disk::openFile(path).transform([&](auto file) {
auto reader = file->reader().buffer();
auto parser = IO::DefParser{reader.stringView(), defaultColor};
return parser.parseDefinitions(status);
});
if (kdl::ci::str_is_equal(".fgd", extension))
{
return IO::Disk::openFile(path).transform([&](auto file) {
auto reader = file->reader().buffer();
auto parser = IO::FgdParser{reader.stringView(), defaultColor, path};
return parser.parseDefinitions(status);
});
}
if (kdl::ci::str_is_equal(".def", extension))
{
return IO::Disk::openFile(path).transform([&](auto file) {
auto reader = file->reader().buffer();
auto parser = IO::DefParser{reader.stringView(), defaultColor};
return parser.parseDefinitions(status);
});
}
if (kdl::ci::str_is_equal(".ent", extension))
{
return IO::Disk::openFile(path).transform([&](auto file) {
auto reader = file->reader().buffer();
auto parser = IO::EntParser{reader.stringView(), defaultColor};
return parser.parseDefinitions(status);
});
}

return Error{"Unknown entity definition format: '" + path.string() + "'"};
}
if (kdl::ci::str_is_equal(".ent", extension))
catch (const ParserException& e)
{
return IO::Disk::openFile(path).transform([&](auto file) {
auto reader = file->reader().buffer();
auto parser = IO::EntParser{reader.stringView(), defaultColor};
return parser.parseDefinitions(status);
});
return Error{e.what()};
}

return Error{"Unknown entity definition format: '" + path.string() + "'"};
}

std::unique_ptr<Assets::EntityModel> GameImpl::doInitializeModel(
Expand Down

0 comments on commit d2d8fc2

Please sign in to comment.