From f4e8e70b5d77c9a6430f64bc223ab0a04b38f815 Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Fri, 15 May 2015 16:00:36 +0200 Subject: Add really simple memory reduction scheme for internal animation player. Holds 30 frames in memory. Could make it check memory instead but that should suffice for now to make sure blender does not crash on me with movie files. Previously the system would load eveything in memory so something like playing caminandes in player would swap after 30 seconds in local computer. --- source/blender/windowmanager/intern/wm_playanim.c | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index 061357c3906..66c502cba53 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -222,6 +222,9 @@ typedef struct PlayAnimPict { } PlayAnimPict; static struct ListBase picsbase = {NULL, NULL}; +/* frames in memory - store them here to for easy deallocation later */ +static struct ListBase inmempicsbase = {NULL, NULL}; +static int added_images = 0; static bool fromdisk = false; static double ptottime = 0.0, swaptime = 0.04; @@ -1130,10 +1133,33 @@ static char *wm_main_playanim_intern(int argc, const char **argv) } if (ibuf) { + LinkData *node; #ifdef USE_IMB_CACHE ps.picture->ibuf = ibuf; #endif + /* really basic memory conservation scheme. Keep frames in a fifo queue */ + node = inmempicsbase.last; + + while (added_images > 30) { + PlayAnimPict *pic = (PlayAnimPict *)node->data; + + if (pic->ibuf != ibuf) { + LinkData *node_tmp; + IMB_freeImBuf(pic->ibuf); + pic->ibuf = NULL; + node_tmp = node->prev; + BLI_freelinkN(&inmempicsbase, node); + added_images--; + node = node_tmp; + } + else { + node = node->prev; + } + } + + BLI_addhead(&inmempicsbase, BLI_genericNodeN(ps.picture)); + added_images++; BLI_strncpy(ibuf->name, ps.picture->name, sizeof(ibuf->name)); -- cgit v1.2.3