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

Đang mở Phù hợp với người mới
#265 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
85/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
computer-graphics

Hướng nghiên cứu

Issue chỉ thẳng vào src/surface/signpost_intrinsic_triangulation.cpp: resolveNewVertex khai báo Vector2 outgoingVec; quanh dòng 678, chỉ gán nó cho các cạnh bên trong gần dòng 736, và gọi outgoingVec.arg() ở dòng 743 trước khi kiểm tra biên ghi đè incomingAngle. Hãy tái hiện bằng đoạn mã Clang Release được cung cấp, áp dụng khởi tạo Vector2::zero(), và xác nhận rằng ví dụ in ra split ok trong Release trong khi các bài kiểm thử surface hiện có vẫn biên dịch và vượt qua.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
1.3k
Fork
188
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nmwsharp/geometry-central

Tất cả issue của nmwsharp/geometry-central

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.