From dd16739a37cb54825e86c0d0000c0e669614d736 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 4 Aug 2026 13:30:59 +0200 Subject: [PATCH] #14452 Guard against fracture without fracture template RimFracture::startMD() and endMD() dereferenced the fracture template without checking for null. A fracture with no template assigned crashed MSW completion export, which calls startMD() for all completions on a well path. --- .../Completions/RimFracture.cpp | 4 ++- ApplicationLibCode/UnitTests/CMakeLists.txt | 1 + .../UnitTests/RimWellPathFracture-Test.cpp | 33 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 ApplicationLibCode/UnitTests/RimWellPathFracture-Test.cpp diff --git a/ApplicationLibCode/ProjectDataModel/Completions/RimFracture.cpp b/ApplicationLibCode/ProjectDataModel/Completions/RimFracture.cpp index 400a20024f..fb23c9c90e 100644 --- a/ApplicationLibCode/ProjectDataModel/Completions/RimFracture.cpp +++ b/ApplicationLibCode/ProjectDataModel/Completions/RimFracture.cpp @@ -363,7 +363,7 @@ cvf::Color3f RimFracture::defaultComponentColor() const //-------------------------------------------------------------------------------------------------- double RimFracture::startMD() const { - if ( fractureTemplate()->orientationType() == RimFractureTemplate::ALONG_WELL_PATH ) + if ( fractureTemplate() && fractureTemplate()->orientationType() == RimFractureTemplate::ALONG_WELL_PATH ) { return fractureMD() - 0.5 * perforationLength(); } @@ -378,6 +378,8 @@ double RimFracture::startMD() const //-------------------------------------------------------------------------------------------------- double RimFracture::endMD() const { + if ( !fractureTemplate() ) return startMD(); + if ( fractureTemplate()->orientationType() == RimFractureTemplate::ALONG_WELL_PATH ) { return startMD() + perforationLength(); diff --git a/ApplicationLibCode/UnitTests/CMakeLists.txt b/ApplicationLibCode/UnitTests/CMakeLists.txt index 7158b399e2..b9c69eaf08 100644 --- a/ApplicationLibCode/UnitTests/CMakeLists.txt +++ b/ApplicationLibCode/UnitTests/CMakeLists.txt @@ -74,6 +74,7 @@ set(SOURCE_UNITTEST_FILES ${CMAKE_CURRENT_LIST_DIR}/Intersect-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RifPerforationIntervalReader-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellPathCompletions-Test.cpp + ${CMAKE_CURRENT_LIST_DIR}/RimWellPathFracture-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellPathValve-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellPathGeometryDef-Test.cpp ${CMAKE_CURRENT_LIST_DIR}/RimWellRftPlot-Test.cpp diff --git a/ApplicationLibCode/UnitTests/RimWellPathFracture-Test.cpp b/ApplicationLibCode/UnitTests/RimWellPathFracture-Test.cpp new file mode 100644 index 0000000000..62a510c92d --- /dev/null +++ b/ApplicationLibCode/UnitTests/RimWellPathFracture-Test.cpp @@ -0,0 +1,33 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2026 Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "gtest/gtest.h" + +#include "RimWellPathFracture.h" + +//-------------------------------------------------------------------------------------------------- +/// A fracture without a fracture template must report a measured depth range without crashing +//-------------------------------------------------------------------------------------------------- +TEST( RimWellPathFractureTest, MeasuredDepthWithoutFractureTemplate ) +{ + RimWellPathFracture fracture; + fracture.setMeasuredDepth( 100.0 ); + + EXPECT_DOUBLE_EQ( 100.0, fracture.startMD() ); + EXPECT_DOUBLE_EQ( 100.0, fracture.endMD() ); +}