mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-19 14:36:34 +00:00
Fixed clipboard paste memory leak in SDL examples. (#1803)
This commit is contained in:
parent
ad2927888b
commit
895647a240
@ -48,6 +48,7 @@ static Uint64 g_Time = 0;
|
|||||||
static bool g_MousePressed[3] = { false, false, false };
|
static bool g_MousePressed[3] = { false, false, false };
|
||||||
static GLuint g_FontTexture = 0;
|
static GLuint g_FontTexture = 0;
|
||||||
static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 };
|
static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 };
|
||||||
|
static char* g_ClipboardTextData = NULL;
|
||||||
|
|
||||||
// OpenGL2 Render function.
|
// OpenGL2 Render function.
|
||||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
||||||
@ -135,7 +136,10 @@ void ImGui_ImplSdlGL2_RenderDrawData(ImDrawData* draw_data)
|
|||||||
|
|
||||||
static const char* ImGui_ImplSdlGL2_GetClipboardText(void*)
|
static const char* ImGui_ImplSdlGL2_GetClipboardText(void*)
|
||||||
{
|
{
|
||||||
return SDL_GetClipboardText();
|
if (g_ClipboardTextData) SDL_free(g_ClipboardTextData);
|
||||||
|
g_ClipboardTextData = SDL_GetClipboardText();
|
||||||
|
|
||||||
|
return g_ClipboardTextData;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSdlGL2_SetClipboardText(void*, const char* text)
|
static void ImGui_ImplSdlGL2_SetClipboardText(void*, const char* text)
|
||||||
@ -285,6 +289,9 @@ void ImGui_ImplSdlGL2_Shutdown()
|
|||||||
SDL_FreeCursor(g_MouseCursors[cursor_n]);
|
SDL_FreeCursor(g_MouseCursors[cursor_n]);
|
||||||
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
|
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
|
||||||
|
|
||||||
|
// Remove previously allocated clipboard text data
|
||||||
|
if (g_ClipboardTextData) SDL_free(g_ClipboardTextData);
|
||||||
|
|
||||||
// Destroy OpenGL objects
|
// Destroy OpenGL objects
|
||||||
ImGui_ImplSdlGL2_InvalidateDeviceObjects();
|
ImGui_ImplSdlGL2_InvalidateDeviceObjects();
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
static Uint64 g_Time = 0;
|
static Uint64 g_Time = 0;
|
||||||
static bool g_MousePressed[3] = { false, false, false };
|
static bool g_MousePressed[3] = { false, false, false };
|
||||||
static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 };
|
static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 };
|
||||||
|
static char* g_ClipboardTextData = NULL;
|
||||||
|
|
||||||
// OpenGL data
|
// OpenGL data
|
||||||
static char g_GlslVersion[32] = "#version 150";
|
static char g_GlslVersion[32] = "#version 150";
|
||||||
@ -183,7 +184,10 @@ void ImGui_ImplSdlGL3_RenderDrawData(ImDrawData* draw_data)
|
|||||||
|
|
||||||
static const char* ImGui_ImplSdlGL3_GetClipboardText(void*)
|
static const char* ImGui_ImplSdlGL3_GetClipboardText(void*)
|
||||||
{
|
{
|
||||||
return SDL_GetClipboardText();
|
if (g_ClipboardTextData) SDL_free(g_ClipboardTextData);
|
||||||
|
g_ClipboardTextData = SDL_GetClipboardText();
|
||||||
|
|
||||||
|
return g_ClipboardTextData;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSdlGL3_SetClipboardText(void*, const char* text)
|
static void ImGui_ImplSdlGL3_SetClipboardText(void*, const char* text)
|
||||||
@ -418,6 +422,9 @@ void ImGui_ImplSdlGL3_Shutdown()
|
|||||||
SDL_FreeCursor(g_MouseCursors[cursor_n]);
|
SDL_FreeCursor(g_MouseCursors[cursor_n]);
|
||||||
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
|
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
|
||||||
|
|
||||||
|
// Remove previously allocated clipboard text data
|
||||||
|
if (g_ClipboardTextData) SDL_free(g_ClipboardTextData);
|
||||||
|
|
||||||
// Destroy OpenGL objects
|
// Destroy OpenGL objects
|
||||||
ImGui_ImplSdlGL3_InvalidateDeviceObjects();
|
ImGui_ImplSdlGL3_InvalidateDeviceObjects();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user