Mercurial > sdl-ios-xcode
comparison src/video/dga/SDL_dgavideo.c @ 102:9162d62280b5
Don't crash if freeing a hardware surface after the video mode has been
reset. Fortunately we keep track of the video memory internally.
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Thu, 12 Jul 2001 23:34:44 +0000 |
parents | 825b2fa28e2e |
children | 2136ea8953f9 |
comparison
equal
deleted
inserted
replaced
101:825b2fa28e2e | 102:9162d62280b5 |
---|---|
738 static void DGA_FreeHWSurface(_THIS, SDL_Surface *surface) | 738 static void DGA_FreeHWSurface(_THIS, SDL_Surface *surface) |
739 { | 739 { |
740 vidmem_bucket *bucket, *freeable; | 740 vidmem_bucket *bucket, *freeable; |
741 | 741 |
742 /* Look for the bucket in the current list */ | 742 /* Look for the bucket in the current list */ |
743 bucket = (vidmem_bucket *)surface->hwdata; | 743 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { |
744 if ( (bucket == NULL) || ! bucket->used ) { | 744 if ( bucket == (vidmem_bucket *)surface->hwdata ) { |
745 return; | 745 break; |
746 } | 746 } |
747 | 747 } |
748 /* Add the memory back to the total */ | 748 if ( bucket && bucket->used ) { |
749 /* Add the memory back to the total */ | |
749 #ifdef DGA_DEBUG | 750 #ifdef DGA_DEBUG |
750 printf("Freeing bucket of %d bytes\n", bucket->size); | 751 printf("Freeing bucket of %d bytes\n", bucket->size); |
751 #endif | 752 #endif |
752 surfaces_memleft += bucket->size; | 753 surfaces_memleft += bucket->size; |
753 | 754 |
754 /* Can we merge the space with surrounding buckets? */ | 755 /* Can we merge the space with surrounding buckets? */ |
755 bucket->used = 0; | 756 bucket->used = 0; |
756 if ( bucket->next && ! bucket->next->used ) { | 757 if ( bucket->next && ! bucket->next->used ) { |
757 #ifdef DGA_DEBUG | 758 #ifdef DGA_DEBUG |
758 printf("Merging with next bucket, for %d total bytes\n", bucket->size+bucket->next->size); | 759 printf("Merging with next bucket, for %d total bytes\n", bucket->size+bucket->next->size); |
759 #endif | 760 #endif |
760 freeable = bucket->next; | 761 freeable = bucket->next; |
761 bucket->size += bucket->next->size; | 762 bucket->size += bucket->next->size; |
762 bucket->next = bucket->next->next; | 763 bucket->next = bucket->next->next; |
763 if ( bucket->next ) { | 764 if ( bucket->next ) { |
764 bucket->next->prev = bucket; | 765 bucket->next->prev = bucket; |
765 } | 766 } |
766 free(freeable); | 767 free(freeable); |
767 } | 768 } |
768 if ( bucket->prev && ! bucket->prev->used ) { | 769 if ( bucket->prev && ! bucket->prev->used ) { |
769 #ifdef DGA_DEBUG | 770 #ifdef DGA_DEBUG |
770 printf("Merging with previous bucket, for %d total bytes\n", bucket->prev->size+bucket->size); | 771 printf("Merging with previous bucket, for %d total bytes\n", bucket->prev->size+bucket->size); |
771 #endif | 772 #endif |
772 freeable = bucket; | 773 freeable = bucket; |
773 bucket->prev->size += bucket->size; | 774 bucket->prev->size += bucket->size; |
774 bucket->prev->next = bucket->next; | 775 bucket->prev->next = bucket->next; |
775 if ( bucket->next ) { | 776 if ( bucket->next ) { |
776 bucket->next->prev = bucket->prev; | 777 bucket->next->prev = bucket->prev; |
777 } | 778 } |
778 free(freeable); | 779 free(freeable); |
780 } | |
779 } | 781 } |
780 surface->pixels = NULL; | 782 surface->pixels = NULL; |
781 surface->hwdata = NULL; | 783 surface->hwdata = NULL; |
782 } | 784 } |
783 | 785 |