Commit: f9547ab3133654f7dac805f9d61c49183fa2046c Author: Campbell Barton Date: Fri May 18 17:32:38 2018 +0200 Branches: blender2.8 https://developer.blender.org/rBf9547ab3133654f7dac805f9d61c49183fa2046c
Fix tools not being initialized on startup =================================================================== M source/blender/editors/screen/workspace_edit.c M source/blender/makesdna/DNA_workspace_types.h M source/blender/windowmanager/WM_api.h M source/blender/windowmanager/intern/wm_toolsystem.c M source/creator/creator.c =================================================================== diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c index fe52e945399..35d916e403d 100644 --- a/source/blender/editors/screen/workspace_edit.c +++ b/source/blender/editors/screen/workspace_edit.c @@ -202,7 +202,7 @@ bool ED_workspace_change( BLI_assert(CTX_wm_workspace(C) == workspace_new); WM_toolsystem_unlink_all(C, workspace_old); - WM_toolsystem_link_all(C, workspace_new); + WM_toolsystem_reinit_all(C, win); return true; } diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h index 12dd2d9962a..24fa0e06d90 100644 --- a/source/blender/makesdna/DNA_workspace_types.h +++ b/source/blender/makesdna/DNA_workspace_types.h @@ -71,8 +71,11 @@ typedef struct bToolRef { struct bToolRef *next, *prev; char idname[64]; + /** Use to avoid initializing the same tool multiple times. */ + short tag; + /** bToolKey (spacetype, mode), used in 'WM_api.h' */ - int space_type; + short space_type; /** * Value depends ont the 'space_type', object mode for 3D view, image editor has own mode too. * RNA needs to handle using item function. diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 0d48cd9ef20..e6b045bc249 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -611,14 +611,12 @@ struct bToolRef_Runtime *WM_toolsystem_runtime_from_context(struct bContext *C); struct bToolRef_Runtime *WM_toolsystem_runtime_find(struct WorkSpace *workspace, const bToolKey *tkey); void WM_toolsystem_unlink(struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey); -void WM_toolsystem_link(struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey); void WM_toolsystem_refresh(struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey); void WM_toolsystem_reinit(struct bContext *C, struct WorkSpace *workspace, const bToolKey *tkey); void WM_toolsystem_unlink_all(struct bContext *C, struct WorkSpace *workspace); -void WM_toolsystem_link_all(struct bContext *C, struct WorkSpace *workspace); void WM_toolsystem_refresh_all(struct bContext *C, struct WorkSpace *workspace); -void WM_toolsystem_reinit_all(struct bContext *C, struct WorkSpace *workspace); +void WM_toolsystem_reinit_all(struct bContext *C, struct wmWindow *win); void WM_toolsystem_ref_set_from_runtime( struct bContext *C, struct WorkSpace *workspace, struct bToolRef *tref, diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c index 122e292985a..3ef5882bc03 100644 --- a/source/blender/windowmanager/intern/wm_toolsystem.c +++ b/source/blender/windowmanager/intern/wm_toolsystem.c @@ -201,13 +201,6 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre } } } -void WM_toolsystem_link(bContext *C, WorkSpace *workspace, const bToolKey *tkey) -{ - bToolRef *tref = WM_toolsystem_ref_find(workspace, tkey); - if (tref) { - toolsystem_ref_link(C, workspace, tref); - } -} static void toolsystem_refresh_ref(bContext *C, WorkSpace *workspace, bToolRef *tref) { @@ -241,30 +234,42 @@ void WM_toolsystem_reinit(bContext *C, WorkSpace *workspace, const bToolKey *tke void WM_toolsystem_unlink_all(struct bContext *C, struct WorkSpace *workspace) { LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { - if (tref->runtime) { - toolsystem_unlink_ref(C, workspace, tref); - } + tref->tag = 0; } -} -void WM_toolsystem_link_all(struct bContext *C, struct WorkSpace *workspace) -{ + LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { if (tref->runtime) { - toolsystem_ref_link(C, workspace, tref); + if (tref->tag == 0) { + toolsystem_unlink_ref(C, workspace, tref); + tref->tag = 1; + } } } } + void WM_toolsystem_refresh_all(struct bContext *C, struct WorkSpace *workspace) { + BLI_assert(0); LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { toolsystem_refresh_ref(C, workspace, tref); } } -void WM_toolsystem_reinit_all(struct bContext *C, struct WorkSpace *workspace) +void WM_toolsystem_reinit_all(struct bContext *C, wmWindow *win) { - LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { - if (tref->runtime) { - toolsystem_reinit_ref(C, workspace, tref); + bScreen *screen = WM_window_get_active_screen(win); + Scene *scene = WM_window_get_active_scene(win); + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + WorkSpace *workspace = WM_window_get_active_workspace(win); + const bToolKey tkey = { + .space_type = sa->spacetype, + .mode = WM_toolsystem_mode_from_spacetype(workspace, scene, sa, sa->spacetype), + }; + bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey); + if (tref) { + if (tref->tag == 0) { + toolsystem_reinit_ref(C, workspace, tref); + tref->tag = 1; + } } } } @@ -304,11 +309,37 @@ void WM_toolsystem_ref_set_from_runtime( void WM_toolsystem_init(bContext *C) { Main *bmain = CTX_data_main(C); - wmWindowManager *wm = bmain->wm.first; - for (wmWindow *win = wm->windows.first; win; win = win->next) { - WorkSpace *workspace = WM_window_get_active_workspace(win); - WM_toolsystem_refresh_all(C, workspace); + BLI_assert(CTX_wm_window(C) == NULL); + + LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) { + LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { + MEM_SAFE_FREE(tref->runtime); + tref->tag = 0; + } + } + + for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { + for (wmWindow *win = wm->windows.first; win; win = win->next) { + CTX_wm_window_set(C, win); + WorkSpace *workspace = WM_window_get_active_workspace(win); + bScreen *screen = WM_window_get_active_screen(win); + Scene *scene = WM_window_get_active_scene(win); + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + const bToolKey tkey = { + .space_type = sa->spacetype, + .mode = WM_toolsystem_mode_from_spacetype(workspace, scene, sa, sa->spacetype), + }; + bToolRef *tref = WM_toolsystem_ref_find(workspace, &tkey); + if (tref) { + if (tref->tag == 0) { + toolsystem_reinit_ref(C, workspace, tref); + tref->tag = 1; + } + } + } + CTX_wm_window_set(C, NULL); + } } } @@ -426,7 +457,6 @@ static void toolsystem_refresh_screen_from_active_tool( static void toolsystem_reinit_with_toolref( bContext *C, WorkSpace *workspace, bToolRef *tref) { - wmOperatorType *ot = WM_operatortype_find("WM_OT_tool_set_by_name", false); /* On startup, Python operatores are not yet loaded. */ if (ot == NULL) { diff --git a/source/creator/creator.c b/source/creator/creator.c index d3fecad2e03..918563dc73b 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -457,6 +457,9 @@ int main( CTX_py_init_set(C, 1); WM_keymap_init(C); + /* Called on load, however Python is not yet initialized, so call again here. */ + WM_toolsystem_init(C); + #ifdef WITH_FREESTYLE /* initialize Freestyle */ FRS_initialize(); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs