# HG changeset patch # User Benjamin Golinvaux # Date 1606303013 -3600 # Node ID 7896aac14587bcfe99a1404cc349d5137e362408 # Parent fb62c1522193f908535302b9358626057b95909f Protected against usage of dying viewport diff -r fb62c1522193 -r 7896aac14587 OrthancStone/Sources/Scene2DViewport/LayerHolder.cpp --- a/OrthancStone/Sources/Scene2DViewport/LayerHolder.cpp Wed Nov 25 12:16:33 2020 +0100 +++ b/OrthancStone/Sources/Scene2DViewport/LayerHolder.cpp Wed Nov 25 12:16:53 2020 +0100 @@ -96,15 +96,18 @@ void LayerHolder::DeleteLayers() { std::unique_ptr lock(GetViewportLock()); - Scene2D& scene = lock->GetController().GetScene(); - - for (int i = 0; i < textLayerCount_ + polylineLayerCount_; ++i) + if (lock) { - ORTHANC_ASSERT(scene.HasLayer(baseLayerIndex_ + i), "No layer"); - scene.DeleteLayer(baseLayerIndex_ + i); + Scene2D& scene = lock->GetController().GetScene(); + + for (int i = 0; i < textLayerCount_ + polylineLayerCount_; ++i) + { + ORTHANC_ASSERT(scene.HasLayer(baseLayerIndex_ + i), "No layer"); + scene.DeleteLayer(baseLayerIndex_ + i); + } + baseLayerIndex_ = -1; + lock->Invalidate(); } - baseLayerIndex_ = -1; - lock->Invalidate(); } PolylineSceneLayer* LayerHolder::GetPolylineLayer(int index /*= 0*/) diff -r fb62c1522193 -r 7896aac14587 OrthancStone/Sources/Scene2DViewport/MeasureTrackers.cpp --- a/OrthancStone/Sources/Scene2DViewport/MeasureTrackers.cpp Wed Nov 25 12:16:33 2020 +0100 +++ b/OrthancStone/Sources/Scene2DViewport/MeasureTrackers.cpp Wed Nov 25 12:16:53 2020 +0100 @@ -60,12 +60,15 @@ std::unique_ptr lock(GetViewportLock()); - if (commitResult_) - lock->GetController().PushCommand(command_); - else - command_->Undo(); + if(lock) + { + if (commitResult_) + lock->GetController().PushCommand(command_); + else + command_->Undo(); - lock->Invalidate(); + lock->Invalidate(); + } } EditMeasureTracker::EditMeasureTracker(boost::weak_ptr viewport, @@ -108,12 +111,15 @@ std::unique_ptr lock(GetViewportLock()); - if (commitResult_) - lock->GetController().PushCommand(command_); - else - command_->Undo(); + if(lock) + { + if (commitResult_) + lock->GetController().PushCommand(command_); + else + command_->Undo(); - lock->Invalidate(); + lock->Invalidate(); + } } } diff -r fb62c1522193 -r 7896aac14587 OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp --- a/OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp Wed Nov 25 12:16:33 2020 +0100 +++ b/OrthancStone/Sources/Volumes/VolumeSceneLayerSource.cpp Wed Nov 25 12:16:53 2020 +0100 @@ -137,59 +137,62 @@ void VolumeSceneLayerSource::Update(const CoordinateSystem3D& plane) { std::unique_ptr lock(GetViewportLock()); - ViewportController& controller = lock->GetController(); - Scene2D& scene = controller.GetScene(); - - assert(slicer_.get() != NULL); - std::unique_ptr slice(slicer_->ExtractSlice(plane)); - - if (slice.get() == NULL) - { - throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); - } - - if (!slice->IsValid()) - { - // The slicer cannot handle this cutting plane: Clear the layer - ClearLayer(); - } - else if (lastPlane_.get() != NULL && - IsSameCuttingPlane(*lastPlane_, plane) && - lastRevision_ == slice->GetRevision()) + if(lock) { - // The content of the slice has not changed: Don't update the - // layer content, but possibly update its style + ViewportController& controller = lock->GetController(); + Scene2D& scene = controller.GetScene(); - if (configurator_.get() != NULL && - configurator_->GetRevision() != lastConfiguratorRevision_ && - scene.HasLayer(layerDepth_)) + assert(slicer_.get() != NULL); + std::unique_ptr slice(slicer_->ExtractSlice(plane)); + + if (slice.get() == NULL) { - configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); + throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); } - } - else - { - LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; - // Content has changed: An update is needed - lastPlane_.reset(new CoordinateSystem3D(plane)); - lastRevision_ = slice->GetRevision(); - std::unique_ptr layer(slice->CreateSceneLayer(configurator_.get(), plane)); - if (layer.get() == NULL) + if (!slice->IsValid()) + { + // The slicer cannot handle this cutting plane: Clear the layer + ClearLayer(); + } + else if (lastPlane_.get() != NULL && + IsSameCuttingPlane(*lastPlane_, plane) && + lastRevision_ == slice->GetRevision()) { - LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; - ClearLayer(); + // The content of the slice has not changed: Don't update the + // layer content, but possibly update its style + + if (configurator_.get() != NULL && + configurator_->GetRevision() != lastConfiguratorRevision_ && + scene.HasLayer(layerDepth_)) + { + configurator_->ApplyStyle(scene.GetLayer(layerDepth_)); + } } else { - LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; - if (configurator_.get() != NULL) + LOG(TRACE) << "VolumeSceneLayerSource::Update -- Content has changed: An update is needed"; + // Content has changed: An update is needed + lastPlane_.reset(new CoordinateSystem3D(plane)); + lastRevision_ = slice->GetRevision(); + + std::unique_ptr layer(slice->CreateSceneLayer(configurator_.get(), plane)); + if (layer.get() == NULL) { - lastConfiguratorRevision_ = configurator_->GetRevision(); - configurator_->ApplyStyle(*layer); + LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() == NULL)"; + ClearLayer(); } + else + { + LOG(TRACE) << "VolumeSceneLayerSource::Update -- (layer.get() != NULL)"; + if (configurator_.get() != NULL) + { + lastConfiguratorRevision_ = configurator_->GetRevision(); + configurator_->ApplyStyle(*layer); + } - scene.SetLayer(layerDepth_, layer.release()); + scene.SetLayer(layerDepth_, layer.release()); + } } } }