diff --git a/sc2/src/libs/graphics/dcqueue.c b/sc2/src/libs/graphics/dcqueue.c index 2f33cb35c..a87192aa7 100644 --- a/sc2/src/libs/graphics/dcqueue.c +++ b/sc2/src/libs/graphics/dcqueue.c @@ -587,3 +587,42 @@ TFB_FlushGraphics (void) RenderedFrames++; BroadcastCondVar (RenderingCond); } + +void +TFB_PurgeDanglingGraphics (void) +{ + Lock_DCQ (-1); + + for (;;) + { + TFB_DrawCommand DC; + + if (!TFB_DrawCommandQueue_Pop (&DC)) + { + // the Queue is now empty. + break; + } + + switch (DC.Type) + { + case TFB_DRAWCOMMANDTYPE_DELETEIMAGE: + { + TFB_Image *DC_image = DC.data.deleteimage.image; + TFB_DrawImage_Delete (DC_image); + break; + } + case TFB_DRAWCOMMANDTYPE_DELETEDATA: + { + void *data = DC.data.deletedata.data; + HFree (data); + break; + } + case TFB_DRAWCOMMANDTYPE_SENDSIGNAL: + { + ClearSemaphore (DC.data.sendsignal.sem); + break; + } + } + } + Unlock_DCQ (); +} diff --git a/sc2/src/libs/graphics/gfx_common.h b/sc2/src/libs/graphics/gfx_common.h index a0ffe9dd3..73ef6569d 100644 --- a/sc2/src/libs/graphics/gfx_common.h +++ b/sc2/src/libs/graphics/gfx_common.h @@ -98,6 +98,7 @@ extern float FrameRate; extern int FrameRateTickBase; void TFB_FlushGraphics (void); // Only call from main thread!! +void TFB_PurgeDanglingGraphics (void); // Only call from main thread as part of shutdown. extern int ScreenWidth; extern int ScreenHeight; diff --git a/sc2/src/uqm.c b/sc2/src/uqm.c index 257d5a92a..0ff1ee7c6 100644 --- a/sc2/src/uqm.c +++ b/sc2/src/uqm.c @@ -470,6 +470,8 @@ main (int argc, char *argv[]) unInitAudio (); uninit_communication (); UninitColorMaps (); + // TODO: Merge into TFB_UninitGraphics when it goes live + TFB_PurgeDanglingGraphics (); // Not yet: TFB_UninitGraphics (); #ifdef NETPLAY