Followup to rB320b7a59c3eed: also handle background image ID refcount when duplicating/freeing View3D.

This commit is contained in:
Bastien Montagne 2014-07-13 15:16:01 +02:00
parent e35845d37c
commit 0fc05c1c03
Notes: blender-bot 2023-02-14 10:14:06 +01:00
Referenced by issue #41411, Undo crashing with background images set
1 changed files with 20 additions and 1 deletions

View File

@ -44,6 +44,7 @@
#include "BKE_context.h"
#include "BKE_icons.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_scene.h"
@ -389,7 +390,16 @@ static SpaceLink *view3d_new(const bContext *C)
static void view3d_free(SpaceLink *sl)
{
View3D *vd = (View3D *) sl;
BGpic *bgpic;
for (bgpic = vd->bgpicbase.first; bgpic; bgpic = bgpic->next) {
if (bgpic->source == V3D_BGPIC_IMAGE) {
id_us_min((ID *)bgpic->ima);
}
else if (bgpic->source == V3D_BGPIC_MOVIE) {
id_us_min((ID *)bgpic->clip);
}
}
BLI_freelistN(&vd->bgpicbase);
if (vd->localvd) MEM_freeN(vd->localvd);
@ -416,6 +426,7 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
{
View3D *v3do = (View3D *)sl;
View3D *v3dn = MEM_dupallocN(sl);
BGpic *bgpic;
/* clear or remove stuff from old */
@ -433,8 +444,16 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
/* copy or clear inside new stuff */
v3dn->defmaterial = NULL;
BLI_duplicatelist(&v3dn->bgpicbase, &v3do->bgpicbase);
for (bgpic = v3dn->bgpicbase.first; bgpic; bgpic = bgpic->next) {
if (bgpic->source == V3D_BGPIC_IMAGE) {
id_us_plus((ID *)bgpic->ima);
}
else if (bgpic->source == V3D_BGPIC_MOVIE) {
id_us_plus((ID *)bgpic->clip);
}
}
v3dn->properties_storage = NULL;