From 1c83354c63a334a57118579d653e642524f23fce Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 23 Jun 2022 16:00:43 +0200 Subject: Fix T99028: crash deleting file output node with color management override One case of copying image formats was not properly using BKE_image_format_copy. To fix this for existing .blend file we need to do versioning, ensuring the curve mapping is properly copied. --- source/blender/blenloader/intern/versioning_300.c | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index eac27bc57ed..844354c8bc3 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -46,6 +46,7 @@ #include "BKE_asset.h" #include "BKE_attribute.h" #include "BKE_collection.h" +#include "BKE_colortools.h" #include "BKE_curve.h" #include "BKE_data_transfer.h" #include "BKE_deform.h" @@ -1620,6 +1621,31 @@ static void versioning_replace_legacy_combined_and_separate_color_nodes(bNodeTre } } +static void version_fix_image_format_copy(Main *bmain, ImageFormatData *format) +{ + /* Fix bug where curves in image format were not properly copied to file output + * node, incorrectly sharing a pointer with the scene settings. Copy the data + * structure now as it should have been done in the first place. */ + if (format->view_settings.curve_mapping) { + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { + if (format != &scene->r.im_format && ELEM(format->view_settings.curve_mapping, + scene->view_settings.curve_mapping, + scene->r.im_format.view_settings.curve_mapping)) { + format->view_settings.curve_mapping = BKE_curvemapping_copy( + format->view_settings.curve_mapping); + break; + } + } + + /* Remove any invalid curves with missing data. */ + if (format->view_settings.curve_mapping->cm[0].curve == NULL) { + BKE_curvemapping_free(format->view_settings.curve_mapping); + format->view_settings.curve_mapping = NULL; + format->view_settings.flag &= ~COLORMANAGE_VIEW_USE_CURVES; + } + } +} + /* NOLINTNEXTLINE: readability-function-size */ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) { @@ -3112,6 +3138,33 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + if (!MAIN_VERSION_ATLEAST(bmain, 303, 4)) { + FOREACH_NODETREE_BEGIN (bmain, ntree, id) { + if (ntree->type == NTREE_COMPOSIT) { + LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + if (node->type == CMP_NODE_OUTPUT_FILE) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + if (sock->storage) { + NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)sock->storage; + version_fix_image_format_copy(bmain, &sockdata->format); + } + } + + if (node->storage) { + NodeImageMultiFile *nimf = (NodeImageMultiFile *)node->storage; + version_fix_image_format_copy(bmain, &nimf->format); + } + } + } + } + } + FOREACH_NODETREE_END; + + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { + version_fix_image_format_copy(bmain, &scene->r.im_format); + } + } + /** * Versioning code until next subversion bump goes here. * -- cgit v1.2.3