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

オープン 初心者向け
#265 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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() の初期化を適用し、既存の surface テストが引き続きビルドおよびパスする一方で、Release で例が split ok を出力することを確認する。

索引モデルが 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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nmwsharp/geometry-central のほかの issue

nmwsharp/geometry-central の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。