From b08bbebf1263342113a55ca920d419911a6944f9 Mon Sep 17 00:00:00 2001 From: Luke Benstead Date: Sun, 5 Mar 2023 20:26:12 +0000 Subject: [PATCH] Mipmap fix --- GL/texture.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/GL/texture.c b/GL/texture.c index cd4ce97..ce2414e 100644 --- a/GL/texture.c +++ b/GL/texture.c @@ -1215,12 +1215,15 @@ void _glAllocateSpaceForMipmaps(TextureObject* active) { GLuint size = active->baseDataSize; /* Copy the data out of the pvr and back to ram */ - GLubyte* temp = (GLubyte*) malloc(size); - memcpy(temp, active->data, size); + GLubyte* temp = NULL; + if(active->data) { + temp = (GLubyte*) malloc(size); + memcpy(temp, active->data, size); - /* Free the PVR data */ - yalloc_free(YALLOC_BASE, active->data); - active->data = NULL; + /* Free the PVR data */ + yalloc_free(YALLOC_BASE, active->data); + active->data = NULL; + } /* Figure out how much room to allocate for mipmaps */ GLuint bytes = _glGetMipmapDataSize(active); @@ -1228,17 +1231,15 @@ void _glAllocateSpaceForMipmaps(TextureObject* active) { active->data = yalloc_alloc_and_defrag(bytes); gl_assert(active->data); - if(!active->data) { + + if(temp) { + /* If there was existing data, then copy it where it should go */ + memcpy(_glGetMipmapLocation(active, 0), temp, size); + + /* We no longer need this */ free(temp); - return; } - /* If there was existing data, then copy it where it should go */ - memcpy(_glGetMipmapLocation(active, 0), temp, size); - - /* We no longer need this */ - free(temp); - /* Set the data offset depending on whether or not this is a * paletted texure */ active->baseDataOffset = _glGetMipmapDataOffset(active, 0);