mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 16:30:32 +00:00
Fixed hot-reloading issues. Hot-reloading may be useful when developing this plug-in but it doesn't play well with free functions used in ImGui interface (limitation of the system I guess). Switched to a custom GImGui which after hot-reload can be redirected to a new module. This fixes a crash caused by GImGui in obsolete module pointing to released resources and guarantees that ImGui code remains functional.
This commit is contained in:
parent
20a7675787
commit
74c794b53e
@ -15,6 +15,15 @@
|
|||||||
#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS
|
#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS
|
||||||
#endif // PLATFORM_XBOXONE
|
#endif // PLATFORM_XBOXONE
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
// Global ImGui context pointer.
|
||||||
|
ImGuiContext* GImGuiContextPtr = nullptr;
|
||||||
|
// Handle to the global ImGui context pointer.
|
||||||
|
ImGuiContext** GImGuiContextPtrHandle = &GImGuiContextPtr;
|
||||||
|
// Get the global ImGui context pointer (GImGui) indirectly to allow redirections in obsolete modules.
|
||||||
|
#define GImGui (*GImGuiContextPtrHandle)
|
||||||
|
#endif // WITH_EDITOR
|
||||||
|
|
||||||
#if PLATFORM_WINDOWS
|
#if PLATFORM_WINDOWS
|
||||||
#include <AllowWindowsPlatformTypes.h>
|
#include <AllowWindowsPlatformTypes.h>
|
||||||
#endif // PLATFORM_WINDOWS
|
#endif // PLATFORM_WINDOWS
|
||||||
@ -51,4 +60,16 @@ namespace ImGuiImplementation
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
ImGuiContext** GetImGuiContextHandle()
|
||||||
|
{
|
||||||
|
return GImGuiContextPtrHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetImGuiContextHandle(ImGuiContext** Handle)
|
||||||
|
{
|
||||||
|
GImGuiContextPtrHandle = Handle;
|
||||||
|
}
|
||||||
|
#endif // WITH_EDITOR
|
||||||
}
|
}
|
@ -10,4 +10,12 @@ namespace ImGuiImplementation
|
|||||||
{
|
{
|
||||||
// Get specific cursor data.
|
// Get specific cursor data.
|
||||||
bool GetCursorData(ImGuiMouseCursor CursorType, FVector2D& OutSize, FVector2D& OutUVMin, FVector2D& OutUVMax, FVector2D& OutOutlineUVMin, FVector2D& OutOutlineUVMax);
|
bool GetCursorData(ImGuiMouseCursor CursorType, FVector2D& OutSize, FVector2D& OutUVMin, FVector2D& OutUVMax, FVector2D& OutOutlineUVMin, FVector2D& OutOutlineUVMax);
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
// Get the handle to the ImGui Context pointer.
|
||||||
|
ImGuiContext** GetImGuiContextHandle();
|
||||||
|
|
||||||
|
// Set the ImGui Context pointer handle.
|
||||||
|
void SetImGuiContextHandle(ImGuiContext** Handle);
|
||||||
|
#endif // WITH_EDITOR
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "Utilities/WorldContextIndex.h"
|
#include "Utilities/WorldContextIndex.h"
|
||||||
|
|
||||||
#if WITH_EDITOR
|
#if WITH_EDITOR
|
||||||
|
#include "ImGuiImplementation.h"
|
||||||
#include "Editor/ImGuiEditor.h"
|
#include "Editor/ImGuiEditor.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -138,8 +139,33 @@ void FImGuiModule::ShutdownModule()
|
|||||||
checkf(ImGuiModuleManager, TEXT("Null ImGui Module Manager. Module manager instance should be deleted during module shutdown."));
|
checkf(ImGuiModuleManager, TEXT("Null ImGui Module Manager. Module manager instance should be deleted during module shutdown."));
|
||||||
delete ImGuiModuleManager;
|
delete ImGuiModuleManager;
|
||||||
ImGuiModuleManager = nullptr;
|
ImGuiModuleManager = nullptr;
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
// When shutting down we leave the global ImGui context pointer and handle pointing to resources that are already
|
||||||
|
// deleted. This can cause troubles after hot-reload when code in other modules calls ImGui interface functions
|
||||||
|
// which are statically bound to the obsolete module. To keep ImGui code functional we can redirect context handle
|
||||||
|
// to point to the new module.
|
||||||
|
FModuleManager::Get().OnModulesChanged().AddLambda([this](FName Name, EModuleChangeReason Reason)
|
||||||
|
{
|
||||||
|
if (Reason == EModuleChangeReason::ModuleLoaded && Name == "ImGui")
|
||||||
|
{
|
||||||
|
FImGuiModule& LoadedModule = FImGuiModule::Get();
|
||||||
|
if (&LoadedModule != this)
|
||||||
|
{
|
||||||
|
ImGuiImplementation::SetImGuiContextHandle(LoadedModule.GetImGuiContextHandle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
#endif // WITH_EDITOR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
ImGuiContext** FImGuiModule::GetImGuiContextHandle()
|
||||||
|
{
|
||||||
|
return ImGuiImplementation::GetImGuiContextHandle();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool FImGuiModule::IsInputMode() const
|
bool FImGuiModule::IsInputMode() const
|
||||||
{
|
{
|
||||||
return CVars::InputEnabled.GetValueOnAnyThread() > 0;
|
return CVars::InputEnabled.GetValueOnAnyThread() > 0;
|
||||||
|
@ -110,4 +110,10 @@ public:
|
|||||||
/** IModuleInterface implementation */
|
/** IModuleInterface implementation */
|
||||||
virtual void StartupModule() override;
|
virtual void StartupModule() override;
|
||||||
virtual void ShutdownModule() override;
|
virtual void ShutdownModule() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
#if WITH_EDITOR
|
||||||
|
virtual struct ImGuiContext** GetImGuiContextHandle();
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user