diff options
author | Jacques Lucke <jacques@blender.org> | 2020-03-06 15:29:58 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-03-06 15:31:15 +0300 |
commit | 50d5050e9c4561d6528a2ac18ad3fbbaa9df6576 (patch) | |
tree | 045c57b22d09f034509cacf4ea737bfd2a7e5df4 /source/blender/blenloader/intern/writefile.c | |
parent | 63bb2007d88b88824094447a745fa21d5fb2f61b (diff) |
Nodes: fix writing socket default values to file
Previously, `writedata` was used to store `bNodeSocket->default_value`.
There are a couple of issues with that:
* Breaks if someone tries to load the file on a big endian system (afaik).
* There is a `/* do not use for structs */` comment on `writedata`.
* Depends on `MEM_allocN_len` which should be avoided in my opinion.
* Now it is more apparent, that this should be handled by callbacks as well.
The part in `readfile.c` should work just fine still. I could also do a case
distinction there, but the code would be the same for every case for now.
Just `sock->default_value = newdataadr(fd, sock->default_value);`.
This might change, if we want to store more complex socket type specific data
that does not fit into a single struct.
Differential Revision: https://developer.blender.org/D7039
Reviewers: brecht
Diffstat (limited to 'source/blender/blenloader/intern/writefile.c')
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index e1cbdc89022..dece8740789 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -963,6 +963,39 @@ static void write_CurveProfile(WriteData *wd, CurveProfile *profile) writestruct(wd, DATA, CurveProfilePoint, profile->path_len, profile->path); } +static void write_node_socket_default_value(WriteData *wd, bNodeSocket *sock) +{ + if (sock->default_value == NULL) { + return; + } + + switch ((eNodeSocketDatatype)sock->type) { + case SOCK_FLOAT: + writestruct(wd, DATA, bNodeSocketValueFloat, 1, sock->default_value); + break; + case SOCK_VECTOR: + writestruct(wd, DATA, bNodeSocketValueVector, 1, sock->default_value); + break; + case SOCK_RGBA: + writestruct(wd, DATA, bNodeSocketValueRGBA, 1, sock->default_value); + break; + case SOCK_BOOLEAN: + writestruct(wd, DATA, bNodeSocketValueBoolean, 1, sock->default_value); + break; + case SOCK_INT: + writestruct(wd, DATA, bNodeSocketValueInt, 1, sock->default_value); + break; + case SOCK_STRING: + writestruct(wd, DATA, bNodeSocketValueString, 1, sock->default_value); + break; + case __SOCK_MESH: + case SOCK_CUSTOM: + case SOCK_SHADER: + BLI_assert(false); + break; + } +} + static void write_node_socket(WriteData *wd, bNodeSocket *sock) { /* actual socket writing */ @@ -972,9 +1005,7 @@ static void write_node_socket(WriteData *wd, bNodeSocket *sock) IDP_WriteProperty(sock->prop, wd); } - if (sock->default_value) { - writedata(wd, DATA, MEM_allocN_len(sock->default_value), sock->default_value); - } + write_node_socket_default_value(wd, sock); } static void write_node_socket_interface(WriteData *wd, bNodeSocket *sock) { @@ -985,9 +1016,7 @@ static void write_node_socket_interface(WriteData *wd, bNodeSocket *sock) IDP_WriteProperty(sock->prop, wd); } - if (sock->default_value) { - writedata(wd, DATA, MEM_allocN_len(sock->default_value), sock->default_value); - } + write_node_socket_default_value(wd, sock); } /* this is only direct data, tree itself should have been written */ static void write_nodetree_nolib(WriteData *wd, bNodeTree *ntree) |