diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 48fa31c91..059ebbd5d 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -696,12 +696,15 @@ void* DebugDraw::AllocateContext() void DebugDraw::FreeContext(void* context) { + ASSERT(context); Memory::DestructItem((DebugDrawContext*)context); Allocator::Free(context); } void DebugDraw::UpdateContext(void* context, float deltaTime) { + if (!context) + context = &GlobalContext; ((DebugDrawContext*)context)->DebugDrawDefault.Update(deltaTime); ((DebugDrawContext*)context)->DebugDrawDepthTest.Update(deltaTime); } diff --git a/Source/Engine/Platform/Base/DragDropHelper.h b/Source/Engine/Platform/Base/DragDropHelper.h index a607cdaec..a5382afd6 100644 --- a/Source/Engine/Platform/Base/DragDropHelper.h +++ b/Source/Engine/Platform/Base/DragDropHelper.h @@ -8,6 +8,18 @@ #include "Engine/Scripting/ManagedCLR/MDomain.h" #include "Engine/Engine/Engine.h" #include "Engine/Platform/Platform.h" +#if USE_EDITOR +#if !COMPILE_WITH_DEBUG_DRAW +#define COMPILE_WITH_DEBUG_DRAW 1 +#define COMPILE_WITH_DEBUG_DRAW_HACK +#endif +#include "Engine/Debug/DebugDraw.h" +#ifdef COMPILE_WITH_DEBUG_DRAW_HACK +#undef COMPILE_WITH_DEBUG_DRAW_HACK +#undef COMPILE_WITH_DEBUG_DRAW +#define COMPILE_WITH_DEBUG_DRAW 0 +#endif +#endif /// /// Async DoDragDrop helper (used for rendering frames during main thread stall). @@ -23,6 +35,10 @@ public: Scripting::GetScriptsDomain()->Dispatch(); while (Platform::AtomicRead(&ExitFlag) == 0) { +#if USE_EDITOR + // Flush any single-frame shapes to prevent memory leaking (eg. via terrain collision debug during scene drawing with PhysicsColliders or PhysicsDebug flag) + DebugDraw::UpdateContext(nullptr, 0.0f); +#endif Engine::OnDraw(); Platform::Sleep(20); }