Skip to content

Fix #8647: Reload surface mesh with selection in Lab demo#9361

Open
chinanuj wants to merge 4 commits intoCGAL:mainfrom
chinanuj:fix-8647-reload-mesh-selection
Open

Fix #8647: Reload surface mesh with selection in Lab demo#9361
chinanuj wants to merge 4 commits intoCGAL:mainfrom
chinanuj:fix-8647-reload-mesh-selection

Conversation

@chinanuj
Copy link

@chinanuj chinanuj commented Mar 4, 2026

Description

Fixes #8647.

This PR addresses the bug where reloading a surface mesh from a file either crashes the Lab demo or fails to reload dependent items (such as selection_item). As noted in the issue description, MainWindow::reloadItem() previously did not account for these dependencies, causing them to be permanently destroyed when the parent mesh was replaced.

Changes Made

Because Scene_polyhedron_selection_item intentionally self-destructs when its parent mesh is removed, a simple C++ pointer dependency check was insufficient. This PR introduces a robust "Cache and Restore" mechanism using Qt's dynamic properties:

  • MainWindow.cpp: Implemented caching inside reloadItem(). The function now scans the scene for dependent items using a parent_mesh_name property tag. It caches their source filename and loader_name before the parent is deleted. After the new parent mesh is loaded and highlighted via setSelectedItem(), the dependencies are explicitly restored from the cached file paths.
  • Selection_plugin.cpp: Updated the load() function to safely rely on the default constructor for memory mapping (preventing 0-vertex load failures and segfaults). Added a dynamic tag (setProperty("parent_mesh_name", target_item->name())) to ensure the selection can be reliably tracked and restored by the main window across reloads.

Testing Performed

  1. Loaded a surface mesh (.off) into the scene and highlighted it.
  2. Loaded a generated .selection.txt file (confirmed vertices and colors applied successfully).
  3. Right-clicked the parent mesh and selected Reload Item from File.
  4. Result: The parent mesh updates successfully without crashing, and the dependent selection items are instantly restored and reattached to the new geometry.

Checklist

  • Code compiles successfully locally.
  • Tested the reload sequence with selection files.
  • Removed all debug print statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lab - reload surface mesh with selection

1 participant