From e239a50c1573fde48f54638689f1e49926d10a05 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Mon, 30 Dec 2024 09:54:04 +0100 Subject: [PATCH] vtkext: Fix a small issue with CollapseFullPath usage in hdri-file and font-file (#1844) - Avoid an issue where CollapseFullPath would generate a path to current directory with the empty string - Refactor the HDRI file to simplify it --- vtkext/private/module/vtkF3DRenderer.cxx | 22 +++++++++++----------- vtkext/private/module/vtkF3DRenderer.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 31e50b1e02..af663b031e 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -637,8 +637,8 @@ void vtkF3DRenderer::ConfigureGridUsingCurrentActors() void vtkF3DRenderer::SetHDRIFile(const std::optional& hdriFile) { // Check HDRI is different than current one - std::optional collapsedHdriFile; - if (hdriFile.has_value()) + std::string collapsedHdriFile; + if (hdriFile.has_value() && !hdriFile.value().empty()) { collapsedHdriFile = vtksys::SystemTools::CollapseFullPath(hdriFile.value()); } @@ -770,25 +770,25 @@ void vtkF3DRenderer::ConfigureHDRIReader() { this->UseDefaultHDRI = false; this->HDRIReader = nullptr; - if (this->HDRIFile.has_value()) + if (!this->HDRIFile.empty()) { - if (!vtksys::SystemTools::FileExists(this->HDRIFile.value(), true)) + if (!vtksys::SystemTools::FileExists(this->HDRIFile, true)) { F3DLog::Print( - F3DLog::Severity::Warning, std::string("HDRI file does not exist ") + this->HDRIFile.value()); + F3DLog::Severity::Warning, std::string("HDRI file does not exist ") + this->HDRIFile); } else { this->HDRIReader = vtkSmartPointer::Take( - vtkImageReader2Factory::CreateImageReader2(this->HDRIFile.value().c_str())); + vtkImageReader2Factory::CreateImageReader2(this->HDRIFile.c_str())); if (this->HDRIReader) { - this->HDRIReader->SetFileName(this->HDRIFile.value().c_str()); + this->HDRIReader->SetFileName(this->HDRIFile.c_str()); } else { F3DLog::Print(F3DLog::Severity::Warning, - std::string("Cannot open HDRI file ") + this->HDRIFile.value() + + std::string("Cannot open HDRI file ") + this->HDRIFile + std::string(". Using default HDRI")); } } @@ -821,8 +821,8 @@ void vtkF3DRenderer::ConfigureHDRIHash() } else { - // Compute HDRI MD5, here we know the HDRIFile has a value - this->HDRIHash = ::ComputeFileHash(this->HDRIFile.value()); + // Compute HDRI MD5, here we know the HDRIFile is not empty + this->HDRIHash = ::ComputeFileHash(this->HDRIFile); } this->HasValidHDRIHash = true; this->CreateCacheDirectory(); @@ -1080,7 +1080,7 @@ void vtkF3DRenderer::ConfigureTextActors() // Font this->DropZoneActor->GetTextProperty()->SetFontFamilyToCourier(); - if (this->FontFile.has_value()) + if (this->FontFile.has_value() && !this->FontFile.value().empty()) { std::string tmpFontFile = vtksys::SystemTools::CollapseFullPath(this->FontFile.value()); if (vtksys::SystemTools::FileExists(tmpFontFile, true)) diff --git a/vtkext/private/module/vtkF3DRenderer.h b/vtkext/private/module/vtkF3DRenderer.h index 40c030da9d..43b529b4a7 100644 --- a/vtkext/private/module/vtkF3DRenderer.h +++ b/vtkext/private/module/vtkF3DRenderer.h @@ -527,7 +527,7 @@ class vtkF3DRenderer : public vtkOpenGLRenderer int GridSubdivisions = 10; double GridColor[3] = { 0.0, 0.0, 0.0 }; - std::optional HDRIFile; + std::string HDRIFile; vtkSmartPointer HDRIReader; bool HasValidHDRIReader = false; bool UseDefaultHDRI = false;