From 0d473e8681c19abd748a8c2faedbea3b92551aea Mon Sep 17 00:00:00 2001
From: Connor McLaughlin <stenzek@gmail.com>
Date: Tue, 26 Jan 2021 01:34:31 +1000
Subject: [PATCH] ImGui: Fix incorrect buffer binding/crash in GLES2

---
 src/frontend-common/imgui_impl_opengl3.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/frontend-common/imgui_impl_opengl3.cpp b/src/frontend-common/imgui_impl_opengl3.cpp
index 7cf5621b5..ac3894348 100644
--- a/src/frontend-common/imgui_impl_opengl3.cpp
+++ b/src/frontend-common/imgui_impl_opengl3.cpp
@@ -187,9 +187,13 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
     if (!g_IsGLES2)
     {
         glBindVertexArray(g_VaoHandle);
+        glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
+        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
     }
     else
     {
+        glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
+        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
         glEnableVertexAttribArray(g_AttribLocationVtxPos);
         glEnableVertexAttribArray(g_AttribLocationVtxUV);
         glEnableVertexAttribArray(g_AttribLocationVtxColor);
@@ -200,9 +204,6 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
         glVertexAttribPointer(g_AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert),
             (GLvoid*)IM_OFFSETOF(ImDrawVert, col));
     }
-
-    glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
-    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
 }
 
 // OpenGL3 Render function.