Fix crash when adding layers through globebrowsing interface due to missing initialization

Fix crash that would happen if the resetting of the tile layer would throw an exception
This commit is contained in:
Alexander Bock
2017-11-09 12:01:35 -05:00
parent 88cf7926ae
commit 5f391de33c
8 changed files with 29 additions and 15 deletions
@@ -171,12 +171,16 @@ Layer::Layer(layergroupid::GroupID id, const ghoul::Dictionary& layerDict,
}
});
_remove.onChange([&](){
if (_tileProvider) {
_tileProvider->reset();
_remove.onChange([&]() {
try {
if (_tileProvider) {
_tileProvider->reset();
}
}
catch (...) {
_parent.deleteLayer(name());
throw;
}
_parent.deleteLayer(name());
});
_typeOption.onChange([&](){
@@ -102,15 +102,17 @@ void LayerGroup::update() {
}
}
void LayerGroup::addLayer(const ghoul::Dictionary& layerDict) {
std::shared_ptr<Layer> LayerGroup::addLayer(const ghoul::Dictionary& layerDict) {
if (!layerDict.hasKeyAndValue<std::string>("Name")) {
LERROR("'Name' must be specified for layer.");
return;
return nullptr;
}
auto layer = std::make_shared<Layer>(_groupId, layerDict, *this);
layer->onChange(_onChangeCallback);
if (hasPropertySubOwner(layer->name())) {
LINFO("Layer with name " + layer->name() + " already exists.");
_levelBlendingEnabled.setVisibility(properties::Property::Visibility::User);
return nullptr;
}
else {
_layers.push_back(layer);
@@ -119,15 +121,16 @@ void LayerGroup::addLayer(const ghoul::Dictionary& layerDict) {
_onChangeCallback();
}
addPropertySubOwner(layer.get());
_levelBlendingEnabled.setVisibility(properties::Property::Visibility::User);
return layer;
}
_levelBlendingEnabled.setVisibility(properties::Property::Visibility::User);
}
void LayerGroup::deleteLayer(const std::string& layerName) {
for (std::vector<std::shared_ptr<Layer>>::iterator it = _layers.begin(); it != _layers.end(); ++it) {
if (it->get()->name() == layerName) {
removePropertySubOwner(it->get());
(*it)->deinitialize();
_layers.erase(it);
update();
if (_onChangeCallback) {
@@ -52,7 +52,7 @@ struct LayerGroup : public properties::PropertyOwner {
/// Updates all layers tile providers within this group
void update();
void addLayer(const ghoul::Dictionary& layerDict);
std::shared_ptr<Layer> addLayer(const ghoul::Dictionary& layerDict);
void deleteLayer(const std::string& layerName);
/// @returns const vector of all layers
@@ -80,9 +80,11 @@ void LayerManager::deinitialize() {
}
}
void LayerManager::addLayer(layergroupid::GroupID groupId, ghoul::Dictionary layerDict) {
std::shared_ptr<Layer> LayerManager::addLayer(layergroupid::GroupID groupId,
ghoul::Dictionary layerDict)
{
ghoul_assert(groupId != layergroupid::Unknown, "Layer group ID must be known");
_layerGroups[groupId]->addLayer(layerDict);
return _layerGroups[groupId]->addLayer(layerDict);
}
void LayerManager::deleteLayer(layergroupid::GroupID groupId, std::string layerName) {
@@ -48,7 +48,7 @@ public:
void initialize();
void deinitialize();
void addLayer(layergroupid::GroupID groupId, ghoul::Dictionary layerDict);
std::shared_ptr<Layer> addLayer(layergroupid::GroupID groupId, ghoul::Dictionary layerDict);
void deleteLayer(layergroupid::GroupID groupId, std::string layerName);
const LayerGroup& layerGroup(size_t groupId);