Paste P465

Forward compatibility after D113
ActivePublic

Authored by Alexander Romanov (a.romanov) on Apr 14 2017, 7:54 PM.
Tags
None
Subscribers
None
1diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
2index c55b426..4549c12 100644
3--- a/source/blender/blenloader/intern/readfile.c
4+++ b/source/blender/blenloader/intern/readfile.c
5@@ -2079,6 +2079,13 @@ static void IDP_DirectLinkGroup(IDProperty *prop, int switch_endian, FileData *f
6​ static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd)
7​ {
8​ switch (prop->type) {
9+ case IDP_INT:
10+ /* hack for keeping forward compatibility after D113 */
11+ if (!(prop->flag & IDP_FLAG_ID))
12+ break;
13+ prop->type = IDP_ID;
14+ prop->flag &= ~IDP_FLAG_ID;
15+ break;
16​ case IDP_GROUP:
17​ IDP_DirectLinkGroup(prop, switch_endian, fd);
18​ break;
19@@ -2139,6 +2146,12 @@ static void IDP_LibLinkProperty(IDProperty *prop, FileData *fd)
20​ return;
21
22​ switch (prop->type) {
23+ case IDP_INT:
24+ /* hack for keeping forward compatibility after D113 */
25+ if (!(prop->flag & IDP_FLAG_ID))
26+ break;
27+ prop->type = IDP_ID;
28+ prop->flag &= ~IDP_FLAG_ID;
29​ case IDP_ID: /* PointerProperty */
30​ {
31​ void *newaddr = newlibadr_us(fd, NULL, IDP_Id(prop));
32diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
33index 57be237..1c24e37 100644
34--- a/source/blender/blenloader/intern/writefile.c
35+++ b/source/blender/blenloader/intern/writefile.c
36@@ -665,7 +665,23 @@ void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd)
37
38​ void IDP_WriteProperty(const IDProperty *prop, void *wd)
39​ {
40+ bool handle_id = prop->type == IDP_ID;
41+ IDProperty *p = (IDProperty *)prop;
42+
43+ /* hack for keeping forward compatibility after D113
44+ * writing IDP_ID as IPD_INT
45+ */
46+ if (handle_id) {
47+ p->flag |= IDP_FLAG_ID;
48+ p->type = IDP_INT;
49+ }
50+
51​ writestruct(wd, DATA, IDProperty, 1, prop);
52+
53+ if (handle_id) {
54+ p->flag &= ~IDP_FLAG_ID;
55+ p->type = IDP_ID;
56+ }
57​ IDP_WriteProperty_OnlyData(prop, wd);
58​ }
59
60diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
61index da0f505..ac3e99b 100644
62--- a/source/blender/makesdna/DNA_ID.h
63+++ b/source/blender/makesdna/DNA_ID.h
64@@ -98,6 +98,7 @@ enum {
65
66​ /*->flag*/
67​ enum {
68+ IDP_FLAG_ID = 1 << 0, /* Hack for solving forward compatibility issue */
69​ IDP_FLAG_GHOST = 1 << 7, /* this means the property is set but RNA will return false when checking
70​ * 'RNA_property_is_set', currently this is a runtime flag */
71​ };