What is the correct way to remove scene nodes from a script object attached to the scene node? I ask as the way I currently do it is not working correctly.
I am attempting to remove a scene node and its components after a set delay. As such, I DelayedExecute a Terminate() method in the Start() method with the given delay (4.5 seconds, in this case).
[code]void Terminate()
{
//scriptFile.ClearDelayedExecute(); Using this causes a null pointer in the AngelScript stack, so I am not using it anymore (removing the ScriptObject should take care of delayed calls anyways)
node.RemoveAllChildren();
node.Remove();
//node.RemoveAllComponents(); This also causes a null pointer exception
}[/code]
Interestingly, the code works fine when I run the program normally, but when I run debug, it receives a SigSegV when it tries to remove the DelayedCall in ScriptInstance::HandleSceneUpdate (see below). I assume that this is because at this point the scene node and components have already been freed/deleted (Adding a break point I was able to observe that the delayedCalls_ vector in the script instance was filled with the values 0xFEEEFEEE, which is win32’s freed memory pattern).
I am considering adding a deadNodeRoot as described in topic1004 (“Invalid/Dead nodes in Lua causing segfaults”), having it remove its children each tick, but before I do so I wanted to be sure that I wasn’t a better solution.
Stack Trace:
#0 00A8CDA4 Urho3D::DelayedCall::operator=(this=0xfeeefeeefeeefeee) (…/…/…/Source/Urho3D/Script/…/Script/…/Script/ScriptEventListener.h:35)
#1 00C286C8 Urho3D::VectorUrho3D::DelayedCall::MoveRange(this=0xbe48c70, dest=0, src=1, count=4277075693) (H:/Projects/Urho/UrhoRepo/Source/Urho3D/Container/…/Container/Vector.h:421)
#2 00C283F7 Urho3D::VectorUrho3D::DelayedCall::Erase(this=0xbe48c70, pos=0, length=1) (H:/Projects/Urho/UrhoRepo/Source/Urho3D/Container/…/Container/Vector.h:252)
#3 0041A460 Urho3D::ScriptInstance::HandleSceneUpdate(this=0xbe48b40, eventType=…, eventData=…) (…\Source\Urho3D\Script\ScriptInstance.cpp:714)
#4 00AC0AAA Urho3D::EventHandlerImplUrho3D::ScriptInstance::Invoke(this=0xbe30350, eventData=…) (…/…/…/Source/Urho3D/Script/…/Core/…/Core/Object.h:263)
#5 0041B84C Urho3D::Object::OnEvent(this=0xbe48b40, sender=0xbb8c870, eventType=…, eventData=…) (…\Source\Urho3D\Core\Object.cpp:71)
#6 0041C192 Urho3D::Object::SendEvent(this=0xbb8c870, eventType=…, eventData=…) (…\Source\Urho3D\Core\Object.cpp:252)
#7 0047CB98 Urho3D::Scene::Update(this=0xbb8c870, timeStep=0.0079020001) (…\Source\Urho3D\Scene\Scene.cpp:617)
#8 0047E12A Urho3D::Scene::HandleUpdate(this=0xbb8c870, eventType=…, eventData=…) (…\Source\Urho3D\Scene\Scene.cpp:966)
#9 00AC2DDA Urho3D::EventHandlerImplUrho3D::Scene::Invoke(this=0xbb8d610, eventData=…) (…/…/…/Source/Urho3D/Scene/…/Scene/…/Scene/…/Scene/…/Core/Object.h:263)
#10 0041B88E Urho3D::Object::OnEvent(this=0xbb8c870, sender=0x4379890, eventType=…, eventData=…) (…\Source\Urho3D\Core\Object.cpp:79)
#11 0041C36F Urho3D::Object::SendEvent(this=0x4379890, eventType=…, eventData=…) (…\Source\Urho3D\Core\Object.cpp:285)
#12 00454640 Urho3D::Engine::Update(this=0x4379890) (…\Source\Urho3D\Engine\Engine.cpp:614)
#13 00453C89 Urho3D::Engine::RunFrame(this=0x4379890) (…\Source\Urho3D\Engine\Engine.cpp:424)
#14 00444512 Urho3D::Application::Run(this=0x4379720) (…\Source\Urho3D\Engine\Application.cpp:83)
#15 004037EE RunApplication() (Game.hpp:32)
#16 0040388D main(argc=1, argv=0x4372b70) (Game.hpp:32)