1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-30 18:34:34 +01:00

Fixed clipboard paste memory leak in SDL examples. (#1803)

This commit is contained in:
Elias Daler 2018-05-09 15:06:53 +03:00 committed by omar
parent ad2927888b
commit 895647a240
2 changed files with 16 additions and 2 deletions

View File

@ -48,6 +48,7 @@ static Uint64 g_Time = 0;
static bool g_MousePressed[3] = { false, false, false };
static GLuint g_FontTexture = 0;
static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 };
static char* g_ClipboardTextData = NULL;
// 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)
@ -135,7 +136,10 @@ void ImGui_ImplSdlGL2_RenderDrawData(ImDrawData* draw_data)
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)
@ -285,6 +289,9 @@ void ImGui_ImplSdlGL2_Shutdown()
SDL_FreeCursor(g_MouseCursors[cursor_n]);
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
// Remove previously allocated clipboard text data
if (g_ClipboardTextData) SDL_free(g_ClipboardTextData);
// Destroy OpenGL objects
ImGui_ImplSdlGL2_InvalidateDeviceObjects();
}

View File

@ -51,6 +51,7 @@
static Uint64 g_Time = 0;
static bool g_MousePressed[3] = { false, false, false };
static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 };
static char* g_ClipboardTextData = NULL;
// OpenGL data
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*)
{
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)
@ -418,6 +422,9 @@ void ImGui_ImplSdlGL3_Shutdown()
SDL_FreeCursor(g_MouseCursors[cursor_n]);
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
// Remove previously allocated clipboard text data
if (g_ClipboardTextData) SDL_free(g_ClipboardTextData);
// Destroy OpenGL objects
ImGui_ImplSdlGL3_InvalidateDeviceObjects();
}