`SignpostIntrinsicTriangulation::splitEdge` on a boundary edge always throws in optimized Clang builds (uninitialized `outgoingVec`)

未關閉 適合新手
#265 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
85/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
cpp

研究方向

該 issue 直接指向 src/surface/signpost_intrinsic_triangulation.cpp:resolveNewVertex 在第 678 行附近宣告 Vector2 outgoingVec;,僅在第 736 行附近為內部邊賦值,並在邊界檢查覆寫 incomingAngle 之前於第 743 行呼叫 outgoingVec.arg()。使用提供的 Clang Release 片段重現,套用 Vector2::zero() 初始化,並確認範例在 Release 中輸出 split ok,同時現有的 surface 測試仍能建置並通過。

由索引模型根據 Issue 內容生成。

描述

Splitting a boundary edge of a SignpostIntrinsicTriangulation throws in Release builds with Clang:

edge split problem: no boundary edge connecting vertices in boundary insertion

Debug builds and GCC builds work fine.

Steps to reproduce
#include "geometrycentral/surface/signpost_intrinsic_triangulation.h"
#include "geometrycentral/surface/surface_mesh_factories.h"

#include <iostream>

using namespace geometrycentral;
using namespace geometrycentral::surface;

int main() {
  std::vector<Vector3> positions = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}};
  std::vector<std::vector<size_t>> faces = {{0, 1, 2}};

  auto [mesh, geometry] = makeManifoldSurfaceMeshAndGeometry(faces, positions);
  SignpostIntrinsicTriangulation intrinsic(*mesh, *geometry);

  intrinsic.splitEdge(intrinsic.intrinsicMesh->edge(0).halfedge(), 0.5);
  std::cout << "split ok" << std::endl;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.25)
project(BoundarySplitRepro LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)

FetchContent_Declare(
  geometry-central
  GIT_REPOSITORY https://github.com/nmwsharp/geometry-central.git
  GIT_TAG 019669ddabda05e0f71fa3587cfb3c1dadf19cb8
  SYSTEM
)
FetchContent_MakeAvailable(geometry-central)

add_executable(boundary_split boundary_split.cc)
target_link_libraries(boundary_split PRIVATE geometry-central)

Release build, throws:

cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++
cmake --build build/Release
build/Release/boundary_split

Debug build, prints split ok:

cmake -S . -B build/Debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clang++
cmake --build build/Debug
build/Debug/boundary_split

Environment: geometry-central 019669d (current master), Clang 18.1.3, Pop!_OS 24.04 (Ubuntu 24.04 based). GCC 13.3 does not show the problem at any optimization level.

Cause

In SignpostIntrinsicTriangulation::resolveNewVertex (src/surface/signpost_intrinsic_triangulation.cpp), Vector2 outgoingVec; (line 678) is only assigned for interior edges (line 736), but outgoingVec.arg() is evaluated in every case (line 743):

double incomingAngle = standardizeAngle(newV, outgoingVec.arg());
if (!inputTraceHe.isInterior()) {
  incomingAngle = 0;
}

For boundary edges the result is overwritten with 0 anyway, but reading the uninitialized value is undefined behavior, and in optimized Clang builds it leads to the exception above.

Fix
-  Vector2 outgoingVec;
+  Vector2 outgoingVec = Vector2::zero();

With this change the example prints split ok in Release builds. I'm happy to open a PR with this change if you'd like.

主要語言
C++
星號
1.3k
分支
188
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

nmwsharp/geometry-central 的其他 Issue

查看 nmwsharp/geometry-central 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。