Instead of deleting layers directly through the property, schedule them to delete in the next frame instead (closes #3357)

This commit is contained in:
Alexander Bock
2024-07-30 13:51:18 +02:00
parent 202e598415
commit 90d05187b4
3 changed files with 17 additions and 1 deletions

View File

@@ -26,6 +26,8 @@
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/engine/globals.h>
#include <openspace/scripting/scriptengine.h>
#include <modules/globebrowsing/src/layergroup.h>
#include <modules/globebrowsing/src/layermanager.h>
#include <modules/globebrowsing/src/tileindex.h>
@@ -320,7 +322,7 @@ Layer::Layer(layers::Group::ID id, const ghoul::Dictionary& layerDict, LayerGrou
_remove.onChange([this]() {
if (_tileProvider) {
_tileProvider->reset();
_parent.deleteLayer(identifier());
_parent.scheduleDeleteLayer(identifier());
}
});

View File

@@ -89,6 +89,11 @@ void LayerGroup::deinitialize() {
void LayerGroup::update() {
ZoneScoped;
for (const std::string& layer : _layersToDelete) {
deleteLayer(layer);
}
_layersToDelete.clear();
_activeLayers.clear();
for (const std::unique_ptr<Layer>& layer : _layers) {
@@ -217,6 +222,10 @@ void LayerGroup::deleteLayer(const std::string& layerName) {
LERROR("Could not find layer " + layerName);
}
void LayerGroup::scheduleDeleteLayer(const std::string& layerName) {
_layersToDelete.push_back(layerName);
}
void LayerGroup::moveLayer(int oldPosition, int newPosition) {
if (_layers.size() == 1) {
ghoul_assert(

View File

@@ -53,6 +53,9 @@ struct LayerGroup : public properties::PropertyOwner {
Layer* addLayer(const ghoul::Dictionary& layerDict);
void deleteLayer(const std::string& layerName);
// The same as `deleteLayer` but executed later before the next frame
void scheduleDeleteLayer(const std::string& layerName);
void moveLayer(int oldPosition, int newPosition);
/**
@@ -81,6 +84,8 @@ private:
std::vector<std::unique_ptr<Layer>> _layers;
std::vector<Layer*> _activeLayers;
std::vector<std::string> _layersToDelete;
properties::BoolProperty _levelBlendingEnabled;
std::function<void(Layer*)> _onChangeCallback;
};