Fix #8647: Reload surface mesh with selection in Lab demo#9361
Open
Fix #8647: Reload surface mesh with selection in Lab demo#9361
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_itemintentionally 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 insidereloadItem(). The function now scans the scene for dependent items using aparent_mesh_nameproperty tag. It caches theirsource filenameandloader_namebefore the parent is deleted. After the new parent mesh is loaded and highlighted viasetSelectedItem(), the dependencies are explicitly restored from the cached file paths.Selection_plugin.cpp: Updated theload()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
.off) into the scene and highlighted it..selection.txtfile (confirmed vertices and colors applied successfully).Checklist