# HG changeset patch # User Sam Lantinga # Date 994980884 0 # Node ID 9162d62280b50b6864c5b0838de800a310f57cf2 # Parent 825b2fa28e2ea8db4b813424fa9e1bf68a0088a4 Don't crash if freeing a hardware surface after the video mode has been reset. Fortunately we keep track of the video memory internally. diff -r 825b2fa28e2e -r 9162d62280b5 src/video/dga/SDL_dgavideo.c --- a/src/video/dga/SDL_dgavideo.c Thu Jul 12 20:42:22 2001 +0000 +++ b/src/video/dga/SDL_dgavideo.c Thu Jul 12 23:34:44 2001 +0000 @@ -740,42 +740,44 @@ vidmem_bucket *bucket, *freeable; /* Look for the bucket in the current list */ - bucket = (vidmem_bucket *)surface->hwdata; - if ( (bucket == NULL) || ! bucket->used ) { - return; + for ( bucket=&surfaces; bucket; bucket=bucket->next ) { + if ( bucket == (vidmem_bucket *)surface->hwdata ) { + break; + } } - - /* Add the memory back to the total */ + if ( bucket && bucket->used ) { + /* Add the memory back to the total */ #ifdef DGA_DEBUG printf("Freeing bucket of %d bytes\n", bucket->size); #endif - surfaces_memleft += bucket->size; + surfaces_memleft += bucket->size; - /* Can we merge the space with surrounding buckets? */ - bucket->used = 0; - if ( bucket->next && ! bucket->next->used ) { + /* Can we merge the space with surrounding buckets? */ + bucket->used = 0; + if ( bucket->next && ! bucket->next->used ) { #ifdef DGA_DEBUG printf("Merging with next bucket, for %d total bytes\n", bucket->size+bucket->next->size); #endif - freeable = bucket->next; - bucket->size += bucket->next->size; - bucket->next = bucket->next->next; - if ( bucket->next ) { - bucket->next->prev = bucket; + freeable = bucket->next; + bucket->size += bucket->next->size; + bucket->next = bucket->next->next; + if ( bucket->next ) { + bucket->next->prev = bucket; + } + free(freeable); } - free(freeable); - } - if ( bucket->prev && ! bucket->prev->used ) { + if ( bucket->prev && ! bucket->prev->used ) { #ifdef DGA_DEBUG printf("Merging with previous bucket, for %d total bytes\n", bucket->prev->size+bucket->size); #endif - freeable = bucket; - bucket->prev->size += bucket->size; - bucket->prev->next = bucket->next; - if ( bucket->next ) { - bucket->next->prev = bucket->prev; + freeable = bucket; + bucket->prev->size += bucket->size; + bucket->prev->next = bucket->next; + if ( bucket->next ) { + bucket->next->prev = bucket->prev; + } + free(freeable); } - free(freeable); } surface->pixels = NULL; surface->hwdata = NULL;