Looking at the following Valgrind dump I see that my Node is gone inside AngelScript.
In my code I use SharedPtr<Node>
to store that node in hope that it will keep reference, but it looks
like I don’t understand the concept:
==18789== Invalid read of size 8
==18789== at 0x8B9AD2: Urho3D::UniquePtr<Urho3D::NodeImpl>::operator->() const (Ptr.h:571)
==18789== by 0x8CCCA3: Urho3D::Node::GetName() const (Node.h:341)
==18789== by 0x8C9645: BTBlackboard::HandlePhysicsPreStep(Urho3D::StringHash, Urho3D::HashMap<Urho3D::StringHash, Urho3D::Variant>&) (BehaviorTree.cpp:83)
==18789== by 0x8CE123: Urho3D::EventHandlerImpl<BTBlackboard>::Invoke(Urho3D::HashMap<Urho3D::StringHash, Urho3D::Variant>&) (Object.h:307)
==18789== by 0xB731A3: Urho3D::Object::OnEvent(Urho3D::Object*, Urho3D::StringHash, Urho3D::HashMap<Urho3D::StringHash, Urho3D::Variant>&) (Object.cpp:113)
==18789== by 0xB73BE1: Urho3D::Object::SendEvent(Urho3D::StringHash, Urho3D::HashMap<Urho3D::StringHash, Urho3D::Variant>&) (Object.cpp:325)
==18789== by 0xC0A8EC: Urho3D::PhysicsWorld::PreStep(float) (PhysicsWorld.cpp:807)
==18789== by 0xC06355: Urho3D::InternalPreTickCallback(btDynamicsWorld*, float) (PhysicsWorld.cpp:71)
==18789== by 0xDB6510: btDiscreteDynamicsWorld::internalSingleStepSimulation(float) (btDiscreteDynamicsWorld.cpp:478)
==18789== by 0xDB647D: btDiscreteDynamicsWorld::stepSimulation(float, int, float) (btDiscreteDynamicsWorld.cpp:455)
==18789== by 0xC07A60: Urho3D::PhysicsWorld::Update(float) (PhysicsWorld.cpp:256)
==18789== by 0xC0A85A: Urho3D::PhysicsWorld::HandleSceneSubsystemUpdate(Urho3D::StringHash, Urho3D::HashMap<Urho3D::StringHash, Urho3D::Variant>&) (PhysicsWorld.cpp:796)
==18789== Address 0x1634cb58 is 312 bytes inside a block of size 352 free'd
==18789== at 0x4C2D360: operator delete(void*) (vg_replace_malloc.c:507)
==18789== by 0x96073C: Urho3D::Node::~Node() (Node.cpp:75)
==18789== by 0xB9AB6D: Urho3D::RefCounted::ReleaseRef() (RefCounted.cpp:65)
==18789== by 0xF0DACD: asCScriptEngine::CallObjectMethod(void*, asSSystemFunctionInterface*, asCScriptFunction*) const (as_scriptengine.cpp:4038)
==18789== by 0xF0D9AA: asCScriptEngine::CallObjectMethod(void*, int) const (as_scriptengine.cpp:4010)
==18789== by 0x8D9BF1: asCContext::ExecuteNext() (as_context.cpp:2771)
==18789== by 0x8D66BC: asCContext::Execute() (as_context.cpp:1297)
==18789== by 0x8BF99C: ScriptBehavior::update(BTBlackboard*) (ScriptBehavior.cpp:111)
==18789== by 0x8CAF72: BTBaseNode::Activate(BTBlackboard*) (BehaviorTree.cpp:167)
==18789== by 0x8CB05F: BTSequenceNode::update(BTBlackboard*) (BehaviorTree.cpp:188)
==18789== by 0x8CAF72: BTBaseNode::Activate(BTBlackboard*) (BehaviorTree.cpp:167)
==18789== by 0x8CB221: BTSelectorNode::update(BTBlackboard*) (BehaviorTree.cpp:242)
How can I prevent of Node being free’d or could I at least get notified about this to prevent data corruption?
Or is there some completely different way to handle such things?