<div dir="ltr">Thanks Michalis. <div>-Doug<br><div>Would a bit flag on a node work?<div>- tested for false before starting node.draw()</div><div>- then set to true when starting node.draw()</div><div>- then set to false when ending node.draw()</div><div>For the script field reference to an ancestor, the script isn't drawing the node, so bit flag wouldn't be tested.</div><div><br></div></div></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, Mar 29, 2026 at 3:14 PM Michalis Kamburelis <<a href="mailto:michalis@castle-engine.io">michalis@castle-engine.io</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sunday, March 29th, 2026 at 20:02, GPU Group via x3d-public <<a href="mailto:x3d-public@web3d.org" target="_blank">x3d-public@web3d.org</a>> wrote:<br>
> There doesn't seem to be anything to stop a scene from being cyclic -- freewrl has no defense against it, and simply crashes likely from stack overflow.-Doug<br>
<br>
The X3D specification does say your example (Group containing itself) is invalid:<br>
<br>
<a href="https://www.web3d.org/documents/specifications/19775-1/V4.0/Part01/concepts.html" rel="noreferrer" target="_blank">https://www.web3d.org/documents/specifications/19775-1/V4.0/Part01/concepts.html</a><br>
<br>
Ctrl+F "acyclic" :)<br>
<br>
"""An X3D scene graph is a directed acyclic graph"""<br>
<br>
"""The transformation hierarchy shall be a directed acyclic graph; a node in the transformation hierarchy that is its own ancestor is considered invalid and shall be ignored. The following is an example of a node in the scene graph that is its own ancestor:..."""<br>
<br>
On a browser side, we indeed must put special care to not allow it. One option is to add to the "maintained mapping" the name->node only once the node is fully finished.<br>
<br>
Note that _some_ way of having cycles in a typical OOP implementation are still possible, e.g. Script field may refer to a parent node of this script. CGE handles it using "weak links", to avoid a loop in ref counting. This makes applying the above advise ("add to the "maintained mapping" the name->node only once the node is fully finished...") not so straightforward, you need to have a mapping to resolve references to current parents too.<br>
<br>
<a href="https://github.com/castle-engine/demo-models/blob/master/x3d/node_cycle_in_script.x3dv" rel="noreferrer" target="_blank">https://github.com/castle-engine/demo-models/blob/master/x3d/node_cycle_in_script.x3dv</a><br>
<br>
<a href="https://github.com/castle-engine/demo-models/blob/master/x3d/node_cycle_in_script.x3d" rel="noreferrer" target="_blank">https://github.com/castle-engine/demo-models/blob/master/x3d/node_cycle_in_script.x3d</a><br>
<br>
Regards,<br>
Michalis<br>
<br>
</blockquote></div>