From cc1af6bb3669fdaeb665a4cfbfedfc53edfd21a2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Aug 2012 15:54:52 +0000 Subject: [PATCH] fix for memory leak playing animations. --- .../blender/windowmanager/intern/wm_playanim.c | 17 ++++++++++++++++- source/creator/creator.c | 14 +++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index 3c7ae3ef584..3c791cb6e5d 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -941,6 +941,9 @@ void playanim(int argc, const char **argv) pupdate_time(); ptottime = 0; + /* newly added in 2.6x, without this images never get freed */ +#define USE_IMB_CACHE + while (ps.go) { if (ps.pingpong) ps.direction = -ps.direction; @@ -967,8 +970,9 @@ void playanim(int argc, const char **argv) if (ptottime > 0.0) ptottime = 0.0; while (ps.picture) { +#ifndef USE_IMB_CACHE if (ibuf != NULL && ibuf->ftype == 0) IMB_freeImBuf(ibuf); - +#endif if (ps.picture->ibuf) { ibuf = ps.picture->ibuf; } @@ -984,6 +988,11 @@ void playanim(int argc, const char **argv) } if (ibuf) { + +#ifdef USE_IMB_CACHE + ps.picture->ibuf = ibuf; +#endif + BLI_strncpy(ibuf->name, ps.picture->name, sizeof(ibuf->name)); /* why only windows? (from 2.4x) - campbell */ @@ -1101,7 +1110,10 @@ void playanim(int argc, const char **argv) #endif /* WITH_QUICKTIME */ /* cleanup */ +#ifndef USE_IMB_CACHE if (ibuf) IMB_freeImBuf(ibuf); +#endif + BLI_freelistN(&picsbase); #if 0 // XXX25 free_blender(); @@ -1115,7 +1127,10 @@ void playanim(int argc, const char **argv) totblock = MEM_get_memory_blocks_in_use(); if (totblock != 0) { + /* prints many bAKey, bArgument's which are tricky to fix */ +#if 0 printf("Error Totblock: %d\n", totblock); MEM_printmemlist(); +#endif } } diff --git a/source/creator/creator.c b/source/creator/creator.c index c9f2892bcce..7479935c179 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -1270,11 +1270,6 @@ int main(int argc, const char **argv) BLI_threadapi_init(); - RNA_init(); - RE_engines_init(); - - init_nodesystem(); - initglobals(); /* blender.c */ IMB_init(); @@ -1295,6 +1290,15 @@ int main(int argc, const char **argv) BLI_argsParse(ba, 1, NULL, NULL); #endif + + /* after level 1 args, this is so playanim skips RNA init */ + RNA_init(); + + RE_engines_init(); + init_nodesystem(); + /* end second init */ + + #if defined(WITH_PYTHON_MODULE) || defined(WITH_HEADLESS) G.background = 1; /* python module mode ALWAYS runs in background mode (for now) */ #else