From 02147f3d9ae6b78632088e36ce28f3634d943050 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Wed, 9 Dec 2015 21:06:36 -0800 Subject: [PATCH] Refactor and avoid NULL deref edge-case - Bug was triggered if ctrlPressed was true when going to background. Foregrounding would reset/NULLify the GLModel, but attempt to render the ctrl key highlighted before the new GLModel was fully created. --- src/video/gltouchkbd.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/video/gltouchkbd.c b/src/video/gltouchkbd.c index 73944b45..634a4f47 100644 --- a/src/video/gltouchkbd.c +++ b/src/video/gltouchkbd.c @@ -111,7 +111,6 @@ static struct { static struct { GLModel *model; - bool modelDirty; // TODO : movement animation int selectedCol; int selectedRow; @@ -460,10 +459,24 @@ static void _destroy_touchkbd_hud(GLModel *parent) { // ---------------------------------------------------------------------------- // GLNode functions -static void gltouchkbd_setup(void) { - LOG("gltouchkbd_setup ..."); +static void gltouchkbd_shutdown(void) { + LOG("gltouchkbd_shutdown ..."); + if (!isAvailable) { + return; + } + + isAvailable = false; mdlDestroyModel(&kbd.model); + kbd.selectedCol = -1; + kbd.selectedRow = -1; + kbd.ctrlPressed = false; +} + +static void gltouchkbd_setup(void) { + LOG("gltouchkbd_setup ... %u", sizeof(kbd)); + + gltouchkbd_shutdown(); kbd.model = mdlCreateQuad(-1.0, -1.0, KBD_OBJ_W, KBD_OBJ_H, MODEL_DEPTH, KBD_FB_WIDTH, KBD_FB_HEIGHT, (GLCustom){ .create = &_create_touchkbd_hud, @@ -484,17 +497,6 @@ static void gltouchkbd_setup(void) { isAvailable = true; } -static void gltouchkbd_shutdown(void) { - LOG("gltouchkbd_shutdown ..."); - if (!isAvailable) { - return; - } - - isAvailable = false; - - mdlDestroyModel(&kbd.model); -} - static void gltouchkbd_render(void) { if (!isAvailable) { return; @@ -521,11 +523,6 @@ static void gltouchkbd_render(void) { _HACKAROUND_GLTEXIMAGE2D_PRE(TEXTURE_ACTIVE_TOUCHKBD, kbd.model->textureName); glTexImage2D(GL_TEXTURE_2D, /*level*/0, TEX_FORMAT_INTERNAL, kbd.model->texWidth, kbd.model->texHeight, /*border*/0, TEX_FORMAT, TEX_TYPE, kbd.model->texPixels); } - if (kbd.modelDirty) { - kbd.modelDirty = false; - glBindBuffer(GL_ARRAY_BUFFER, kbd.model->posBufferName); - glBufferData(GL_ARRAY_BUFFER, kbd.model->positionArraySize, kbd.model->positions, GL_DYNAMIC_DRAW); - } glUniform1i(texSamplerLoc, TEXTURE_ID_TOUCHKBD); glhud_renderDefault(kbd.model); }