SDK/DebugComponent: Fix crash when removing the debug component while active
This commit is contained in:
parent
960eb5f475
commit
164633e518
|
|
@ -41,6 +41,7 @@ namespace Ndk
|
||||||
constexpr DebugDrawFlags DebugDraw_None = 0;
|
constexpr DebugDrawFlags DebugDraw_None = 0;
|
||||||
|
|
||||||
class DebugComponent;
|
class DebugComponent;
|
||||||
|
class GraphicsComponent;
|
||||||
|
|
||||||
using DebugComponentHandle = Nz::ObjectHandle<DebugComponent>;
|
using DebugComponentHandle = Nz::ObjectHandle<DebugComponent>;
|
||||||
|
|
||||||
|
|
@ -65,8 +66,14 @@ namespace Ndk
|
||||||
static ComponentIndex componentIndex;
|
static ComponentIndex componentIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void DetachDebugRenderables(GraphicsComponent& gfxComponent);
|
||||||
|
|
||||||
inline const Nz::InstancedRenderableRef& GetDebugRenderable(DebugDraw option) const;
|
inline const Nz::InstancedRenderableRef& GetDebugRenderable(DebugDraw option) const;
|
||||||
inline DebugDrawFlags GetEnabledFlags() const;
|
inline DebugDrawFlags GetEnabledFlags() const;
|
||||||
|
|
||||||
|
void OnComponentDetached(BaseComponent& component) override;
|
||||||
|
void OnDetached() override;
|
||||||
|
|
||||||
inline void UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable);
|
inline void UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable);
|
||||||
inline void UpdateEnabledFlags(DebugDrawFlags flags);
|
inline void UpdateEnabledFlags(DebugDrawFlags flags);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,33 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||||
|
|
||||||
#include <NDK/Components/DebugComponent.hpp>
|
#include <NDK/Components/DebugComponent.hpp>
|
||||||
|
#include <NDK/Components/GraphicsComponent.hpp>
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
|
void DebugComponent::DetachDebugRenderables(GraphicsComponent& gfxComponent)
|
||||||
|
{
|
||||||
|
for (auto& renderable : m_debugRenderables)
|
||||||
|
{
|
||||||
|
if (renderable)
|
||||||
|
{
|
||||||
|
gfxComponent.Detach(renderable);
|
||||||
|
renderable.Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugComponent::OnComponentDetached(BaseComponent& component)
|
||||||
|
{
|
||||||
|
if (IsComponent<GraphicsComponent>(component))
|
||||||
|
DetachDebugRenderables(static_cast<GraphicsComponent&>(component));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugComponent::OnDetached()
|
||||||
|
{
|
||||||
|
if (m_entity->HasComponent<GraphicsComponent>())
|
||||||
|
DetachDebugRenderables(m_entity->GetComponent<GraphicsComponent>());
|
||||||
|
}
|
||||||
|
|
||||||
ComponentIndex DebugComponent::componentIndex;
|
ComponentIndex DebugComponent::componentIndex;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue