Skip to content

Commit

Permalink
#5231: MapImporter destructor can also throw exceptions, move into tr…
Browse files Browse the repository at this point in the history
…y block
  • Loading branch information
codereader committed Aug 12, 2020
1 parent fadc0a2 commit b6afb82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
1 change: 1 addition & 0 deletions radiant/ui/MapFileProgressHandler.cpp
Expand Up @@ -58,6 +58,7 @@ void MapFileProgressHandler::handleFileOperation(map::FileOperation& msg)
// A previous _blocker update might indicate a cancel operation, propagate this info
if (_wasCancelled)
{
_wasCancelled = false;
msg.cancelOperation();
return;
}
Expand Down
67 changes: 30 additions & 37 deletions radiantcore/map/MapResource.cpp
Expand Up @@ -316,56 +316,49 @@ RootNodePtr MapResource::loadMapNodeFromStream(std::istream& stream, const std::

bool MapResource::loadFile(std::istream& mapStream, const MapFormat& format, const RootNodePtr& root, const std::string& filename)
{
// Our importer taking care of scene insertion
MapImporter importFilter(root, mapStream);

// Acquire a map reader/parser
IMapReaderPtr reader = format.getMapReader(importFilter);

try
{
try
{
rMessage() << "Using " << format.getMapFormatName() << " format to load the data." << std::endl;
// Our importer taking care of scene insertion
MapImporter importFilter(root, mapStream);

// Start parsing
reader->readFromStream(mapStream);
// Acquire a map reader/parser
IMapReaderPtr reader = format.getMapReader(importFilter);

// Prepare child primitives
scene::addOriginToChildPrimitives(root);
rMessage() << "Using " << format.getMapFormatName() << " format to load the data." << std::endl;

if (!format.allowInfoFileCreation())
{
// No info file handling, just return success
return true;
}
// Start parsing
reader->readFromStream(mapStream);

// Check for an additional info file
loadInfoFile(root, filename, importFilter.getNodeMap());
// Prepare child primitives
scene::addOriginToChildPrimitives(root);

if (!format.allowInfoFileCreation())
{
// No info file handling, just return success
return true;
}
catch (map::FileOperation::OperationCancelled&)
{
// Clear out the root node, otherwise we end up with half a map
scene::NodeRemover remover;
root->traverseChildren(remover);

throw OperationException(_("Map loading cancelled"));
}
catch (IMapReader::FailureException & e)
{
// Clear out the root node, otherwise we end up with half a map
scene::NodeRemover remover;
root->traverseChildren(remover);
// Check for an additional info file
loadInfoFile(root, filename, importFilter.getNodeMap());

throw OperationException(
fmt::format(_("Failure reading map file:\n{0}\n\n{1}"), filename, e.what()));
}
return true;
}
catch (map::FileOperation::OperationCancelled&)
{
// Clear out the root node, otherwise we end up with half a map
scene::NodeRemover remover;
root->traverseChildren(remover);

throw OperationException(_("Map loading cancelled"));
}
catch (const OperationException& ex)
catch (IMapReader::FailureException& e)
{
rError() << ex.what() << std::endl;
// Clear out the root node, otherwise we end up with half a map
scene::NodeRemover remover;
root->traverseChildren(remover);

throw OperationException(
fmt::format(_("Failure reading map file:\n{0}\n\n{1}"), filename, e.what()));
}
}

Expand Down

0 comments on commit b6afb82

Please sign in to comment.