From 6219d0d145d3f2e6bd30be1c91e952e18db44e74 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 30 Sep 2020 14:49:42 +0200 Subject: Fix (unreported) design flow in how workspace's relation data are read from .blend file. Relying on pointer addresses across different data-blocks is extremely not recommended (and should be strictly forbidden ideally), in particular in direct_link step of blend file reading. - It assumes a specific order in reading of data, which is not ensured in future, and is in any case a very bad, non explicit, hidden dependency on behaviors of other parts of the codebase. - It is intrinsically unsafe (as in, it makes writing bad code and making mistakes easy, see e.g. fix in rB84b3f6e049b35f9). - It makes advanced handling of data-blocks harder (thinking about partial undo code e.g., even though in this specific case it was not an issue as we do not re-read neither windowmanagers nor worspaces during undo). New code uses windows' `winid` instead as 'anchor' to find again proper workspace hook in windows at read time. As a bonus, it will also cleanup the list of relations from any invalid ones (afaict it was never done previously). Differential Revision: https://developer.blender.org/D9073 --- source/blender/blenkernel/BKE_workspace.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source/blender/blenkernel/BKE_workspace.h') diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h index 5ff1ba2c6f5..82a4e5fe08e 100644 --- a/source/blender/blenkernel/BKE_workspace.h +++ b/source/blender/blenkernel/BKE_workspace.h @@ -36,7 +36,8 @@ struct bToolRef; struct WorkSpace *BKE_workspace_add(struct Main *bmain, const char *name); void BKE_workspace_remove(struct Main *bmain, struct WorkSpace *workspace); -struct WorkSpaceInstanceHook *BKE_workspace_instance_hook_create(const struct Main *bmain); +struct WorkSpaceInstanceHook *BKE_workspace_instance_hook_create(const struct Main *bmain, + const int winid); void BKE_workspace_instance_hook_free(const struct Main *bmain, struct WorkSpaceInstanceHook *hook); @@ -83,11 +84,13 @@ void BKE_workspace_active_set(struct WorkSpaceInstanceHook *hook, struct WorkSpaceLayout *BKE_workspace_active_layout_get(const struct WorkSpaceInstanceHook *hook) GETTER_ATTRS; void BKE_workspace_active_layout_set(struct WorkSpaceInstanceHook *hook, + const int winid, struct WorkSpace *workspace, struct WorkSpaceLayout *layout) SETTER_ATTRS; struct bScreen *BKE_workspace_active_screen_get(const struct WorkSpaceInstanceHook *hook) GETTER_ATTRS; void BKE_workspace_active_screen_set(struct WorkSpaceInstanceHook *hook, + const int winid, struct WorkSpace *workspace, struct bScreen *screen) SETTER_ATTRS; -- cgit v1.2.3