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.
This commit is contained in:
Aaron Culliney 2015-12-09 21:06:36 -08:00
parent 791bb91843
commit 02147f3d9a

View File

@ -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);
}