forked from 1b-agent/opencadstudio-upstream
fix(blocks): prevent circular block nesting and cut render cycles
Introduce would_create_cycle in block_service to prevent recursive block definitions with case-insensitive matching across block records. Enforce cycle refusal at INSERT commit in BEDIT and during block redefinition (redefine_block_raw) with a shared error message. Ensure render-time recursion truncates safely with a one-time session warning on cyclic documents.
This commit is contained in:
1 parent
59bb6faabd
commit
9c08e8a3ed
8 files changed
+435
-24
No files matched your search
@@ -982,6 +982,35 @@ impl OpenCADStudio {
|
||||
|
||||
pub(super) fn handle_attreq_needed(&mut self, block_name: String) -> Option<Task<Message>> {
|
||||
let i = self.active_tab;
|
||||
// When active space is a block editor session (BEDIT), refuse inserting
|
||||
// any block that would create a circular nesting dependency.
|
||||
if let Some(edit_handle) = self.tabs[i].scene.block_edit_block {
|
||||
let container_name = self.tabs[i]
|
||||
.scene
|
||||
.document
|
||||
.block_records
|
||||
.iter()
|
||||
.find(|br| br.handle == edit_handle)
|
||||
.map(|br| br.name.clone());
|
||||
if let Some(container) = container_name {
|
||||
if crate::scene::block_service::would_create_cycle(
|
||||
&self.tabs[i].scene.document,
|
||||
&container,
|
||||
&block_name,
|
||||
) {
|
||||
self.command_line.push_error(
|
||||
&crate::scene::block_service::circular_dependency_error(
|
||||
&container,
|
||||
&block_name,
|
||||
),
|
||||
);
|
||||
self.tabs[i].active_cmd = None;
|
||||
self.tabs[i].snap_result = None;
|
||||
self.tabs[i].scene.clear_preview_wire();
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Collect the full AttributeDefinitions owned by this block
|
||||
// record so each created attribute keeps its geometry (#255).
|
||||
let mut attdefs: Vec<codec::entities::AttributeDefinition> = {
|
||||
|
||||
Reference in new issue
Block a user