diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-05-24 16:39:15 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-05-24 16:39:15 +0300 |
commit | 3de9db96508309646d2d715eee483ca5ff909b87 (patch) | |
tree | 3bc5347f091a6a8bcab18801f2d46d6cecc4242e /source/blender/blenloader/intern/versioning_270.c | |
parent | f4074ce8d747d6329a00aca436dab899e710750c (diff) |
Proper fix for crash loading old files with compositor
Now we keep all links around, even for sockets which were
implicitly renamed. And also ensuring new sockets have proper
storage.
Diffstat (limited to 'source/blender/blenloader/intern/versioning_270.c')
-rw-r--r-- | source/blender/blenloader/intern/versioning_270.c | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 06eb631f669..d2f43a2d79e 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -249,6 +249,41 @@ static void do_version_hue_sat_node(bNodeTree *ntree, bNode *node) node->storage = NULL; } +static void do_versions_compositor_render_passes_storage(bNode *node) +{ + int pass_index = 0; + const char *sockname; + for (bNodeSocket *sock = node->outputs.first; sock && pass_index < 31; sock = sock->next, pass_index++) { + if (sock->storage == NULL) { + NodeImageLayer *sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer"); + sock->storage = sockdata; + BLI_strncpy(sockdata->pass_name, node_cmp_rlayers_sock_to_pass(pass_index), sizeof(sockdata->pass_name)); + + if (pass_index == 0) sockname = "Image"; + else if (pass_index == 1) sockname = "Alpha"; + else sockname = node_cmp_rlayers_sock_to_pass(pass_index); + BLI_strncpy(sock->name, sockname, sizeof(sock->name)); + } + } +} + +static void do_versions_compositor_render_passes(bNodeTree *ntree) +{ + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_R_LAYERS) { + /* First we make sure existing sockets have proper names. + * This is important because otherwise verification will + * drop links from sockets which were renamed. + */ + do_versions_compositor_render_passes_storage(node); + /* Make sure new sockets are properly created. */ + node_verify_socket_templates(ntree, node); + /* Make sure all possibly created sockets have proper storage. */ + do_versions_compositor_render_passes_storage(node); + } + } +} + void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) { if (!MAIN_VERSION_ATLEAST(main, 270, 0)) { @@ -1612,25 +1647,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) FOREACH_NODETREE(main, ntree, id) { if (ntree->type == NTREE_COMPOSIT) { - bNode *node; - for (node = ntree->nodes.first; node; node = node->next) { - if (node->type == CMP_NODE_R_LAYERS) { - int pass_index = 0; - const char *sockname; - for (bNodeSocket *sock = node->outputs.first; sock && pass_index < 31; sock = sock->next, pass_index++) { - if (sock->storage == NULL) { - NodeImageLayer *sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer"); - sock->storage = sockdata; - BLI_strncpy(sockdata->pass_name, node_cmp_rlayers_sock_to_pass(pass_index), sizeof(sockdata->pass_name)); - - if (pass_index == 0) sockname = "Image"; - else if (pass_index == 1) sockname = "Alpha"; - else sockname = node_cmp_rlayers_sock_to_pass(pass_index); - BLI_strncpy(sock->name, sockname, sizeof(sock->name)); - } - } - } - } + do_versions_compositor_render_passes(ntree); } } FOREACH_NODETREE_END } |