Igor_de Posted January 25, 2013 Share Posted January 25, 2013 I get exception when try delete node with child, what i doing wrong? Simple code. void addIsland(string nodeName, long dbId) { Node node = node_append(engine.world.loadNode(nodeName));// node in GC Island::Island island = new Island::Island(node, dbId);//save node in inner class islands[dbId] = island; } void addSubIsland(long dbId, string nodeName) { Island::Island island = islands[dbId]; Node node = engine.world.loadNode(nodeName); // no new, no GC island.node.addChild(node); // parent node will delete child } void removeIsland(long dbId) { Island::Island island = islands[dbId]; node_delete(island.node); // exception islands.remove(dbId); delete island; } First-chance exception at 0x76b9c41f in World_d.exe: Microsoft C++ exception: char at memory location 0x0085b664.. ExternClass::destructor(): object is not constructed in "class NodeReference *" classStack dump:0x0000: int: 370x0001: Node 10536AC0 external (53:67:67)0x0002: int: 00x0003: Node 0E89CC00 external (53:65:65)0x0004: int: 00x0005: Node 0E822650 internal (53:59:59)0x0006: int: 60x0007: Node 0E815DB0 internal (53:0:0)Call stack:00: 0x000000e8 node_delete()01: 0x000000e8 node_delete()02: 0x000000e8 node_delete()03: 0x000000e8 node_delete()04: 0x000000e8 node_delete()05: 0x000067d7 removeIsland()Disassemble:0x00000118: callcd0x00000119: pushc int: 00x0000011b: ret0x0000011c: jmp 0x00000402node_load(name)0x0000011e: getv name Link to comment
frustum Posted January 25, 2013 Share Posted January 25, 2013 You have to call node_append function for the each engine.world.loadNode() result.Because this function returns a new unique node instance: Node node = node_append(engine.world.loadNode(nodeName)); Link to comment
Igor_de Posted January 25, 2013 Author Share Posted January 25, 2013 The same error void addIsland(string nodeName, long dbId) { Node node = node_append(engine.world.loadNode(nodeName));// node in GC Island::Island island = new Island::Island(node, dbId);//save node in inner class islands[dbId] = island; } void addSubIsland(long dbId, string nodeName) { Island::Island island = islands[dbId]; Node node = node_append(engine.world.loadNode(nodeName)); // node in GC island.node.addChild(node_remove(node)); // delete from GC, parent node will delete child } void removeIsland(long dbId) { Island::Island island = islands[dbId]; node_delete(island.node); // exception islands.remove(dbId); delete island; } First-chance exception at 0x76b9c41f in World_d.exe: Microsoft C++ exception: char at memory location 0x003ab4b4..ExternClass::destructor(): object is not constructed in "class NodeReference *" classStack dump:0x0000: int: 370x0001: Node 133E6930 external (53:276:276)0x0002: int: 00x0003: Node 1784F7A0 external (53:275:275)0x0004: int: 00x0005: Node 177D2E90 external (53:59:59)0x0006: int: 60x0007: Node 177C25C0 external (53:0:0)Call stack:00: 0x000000e8 node_delete()01: 0x000000e8 node_delete()02: 0x000000e8 node_delete()03: 0x000000e8 node_delete()04: 0x000000e8 node_delete()05: 0x000068e7 removeIsland()Disassemble:0x00000118: callcd0x00000119: pushc int: 00x0000011b: ret0x0000011c: jmp 0x00000402node_load(name)0x0000011e: getv name Link to comment
frustum Posted January 25, 2013 Share Posted January 25, 2013 Do not remove node: island.node.addChild(node); Link to comment
Igor_de Posted January 25, 2013 Author Share Posted January 25, 2013 Why in the documentation? Here, the script takes ownership of both MyNode and its child NodeChild. Node node_remove(Node node) releases the script ownership of the given node and its children. (Do not forget to set another owner!) void node_delete(Node node) deletes the parent node together with its children. Before calling this function, the node should be appended for the script to take ownership.Source code (UnigineScript) Node node = engine.world.loadNode("my.node");node.addChild(class_remove(new NodeDummy()));node_delete(node_append(node)); Link to comment
Igor_de Posted January 25, 2013 Author Share Posted January 25, 2013 How can I check that all children removed? Link to comment
manguste Posted January 30, 2013 Share Posted January 30, 2013 Why in the documentation? Here, the script takes ownership of both MyNode and its child NodeChild. Node node_remove(Node node) releases the script ownership of the given node and its children. (Do not forget to set another owner!) void node_delete(Node node) deletes the parent node together with its children. Before calling this function, the node should be appended for the script to take ownership. Source code (UnigineScript) Node node = engine.world.loadNode("my.node"); node.addChild(class_remove(new NodeDummy())); node_delete(node_append(node)); It's in the documentation since this code works. Here, we've got an orphan node with an orphan child (since we released script ownership over NodeDummy). Since both of them are appended to the script, they can be safely deleted. That should be the case in your code too: if you delete a parent with a child, make sure first that both are handled by the script. How can I check that all children removed? You can use engine.world.isNode() function. Link to comment
Recommended Posts