<div dir="auto">Thanks for recognizing the issue, and suggesting a solution. All nodes with children, or other mutable valued parameters, are likely affected.<div dir="auto"><br></div><div dir="auto">Andreas<br><div dir="auto"><br><div data-smartmail="gmail_signature" dir="auto">---on the phone---</div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 12, 2020, 9:26 PM <a href="mailto:vmarchetti@kshell.com">vmarchetti@kshell.com</a> <<a href="mailto:vmarchetti@kshell.com">vmarchetti@kshell.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">This is an unfortunate and common bug that occurs in Python.<div><br></div><div>In the definition of the class Scene (around line 8795 of x3d.py) is this definition of the __init__ function for Scene:</div><div><br></div><div><div>    def __init__(self, children=list()):</div><div>        self.children = children</div><div><br></div><div>This code is read once when the x3d.py module is loaded, and it creates a class-level default value for the children argument.</div><div>If you ever use the default value by calling Scene() {with no parameter}, this class-level instance of list is modified, and this SAME INSTANCE of list</div><div>if used for any further calls of Scene()</div><div><br></div><div>The way to avoid this is to define the __init__ function this way:</div><div><br></div><div><span style="white-space:pre-wrap">      </span>def __init__(self, children=None):</div><div><span style="white-space:pre-wrap">               </span>if children is None:</div><div><span style="white-space:pre-wrap">                     </span>self.children = list() # creates a new empty list for each Scene instance</div><div><span style="white-space:pre-wrap">                </span>else:</div><div><span style="white-space:pre-wrap">                    </span>self.children = children</div><div><br></div><div><br></div><div>Vince Marchetti</div><div><br></div><div><br><blockquote type="cite"><div>On May 12, 2020, at 5:59 PM, Andreas Plesch <<a href="mailto:andreasplesch@gmail.com" target="_blank" rel="noreferrer">andreasplesch@gmail.com</a>> wrote:</div><br><div><div dir="ltr">I discovered a simple workaround. Always pass a children parameter, even if empty.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 12, 2020 at 5:16 PM Andreas Plesch <<a href="mailto:andreasplesch@gmail.com" target="_blank" rel="noreferrer">andreasplesch@gmail.com</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"><div dir="ltr">Hi,<br><br>after some debugging I discovered another issue with x3d.py. It can be boiled down t o a few lines of code:<br><br><font face="monospace">import x3d.x3d as x<br><br>my_scene = x.Scene()<br>group = x.Group()<br>my_scene.children.append(group)<br>print(my_scene.XML())<br><br>=> output<br>=> <Scene><br>=>  <Group/><br>=> </Scene><br><br>my_other_scene = x.Scene()<br>print(my_other_scene.XML())<br><br>=> output<br>=> <Scene><br>=>  <Group/><br>=> </Scene><br><br></font>I think my_other_scene should be empty but remembers the content of the first scene.<div>Can you reproduce that ?</div><div>On the other hand this works (in a new session):</div><div><font face="monospace"><br></font></div><div><font face="monospace">my_scene = x.Scene( children = [x.Group()] )<br>print(my_scene.XML())<br><br>=> output<br>=> <Scene><br>=>  <Group/><br>=> </Scene><br><br>my_other_scene = x.Scene()<br>print(my_other_scene.XML()) </font> <br></div><div><br></div><div><font face="monospace">=> output<br>=> <Scene><br>=> </Scene></font><br></div><div><br>-- <br>Andreas Plesch<br>Waltham, MA 02453</div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Andreas Plesch<br>Waltham, MA 02453</div></div></div>
_______________________________________________<br>x3d-public mailing list<br><a href="mailto:x3d-public@web3d.org" target="_blank" rel="noreferrer">x3d-public@web3d.org</a><br><a href="http://web3d.org/mailman/listinfo/x3d-public_web3d.org" target="_blank" rel="noreferrer">http://web3d.org/mailman/listinfo/x3d-public_web3d.org</a><br></div></blockquote></div><br></div></div></blockquote></div>