Ensure dependency graph exists before initializing editors

Will help entering sculpt mode on file load by making it possible
to fully initialize sculpt session. The goal is to make sure PBVH
exists since the very beginning of file open (missing PBVH is a
reason why object is not visible before first stroke).

This is not enough yet to fully solve the issue, since entering
sculpt mode tags object for Copy-on-Write update, which frees
PBVH.
This commit is contained in:
Sergey Sharybin 2018-07-05 15:30:56 +02:00
parent c1678a3723
commit d192d72312
Notes: blender-bot 2023-02-14 03:53:53 +01:00
Referenced by commit 81a93df6d2, Fix crash when startup file has an image in it
Referenced by issue #61063, Function from Python not being loaded for Driver when project opened
4 changed files with 29 additions and 26 deletions

View File

@ -864,15 +864,6 @@ void BKE_sculpt_update_mesh_elements(
Depsgraph *depsgraph, Scene *scene, Sculpt *sd, Object *ob,
bool need_pmap, bool need_mask)
{
if (depsgraph == NULL) {
/* Happens on file load.
*
* We do nothing in this case, it will be taken care about on depsgraph
* evaluation.
*/
return;
}
SculptSession *ss = ob->sculpt;
Mesh *me = BKE_object_get_original_mesh(ob);
MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob);

View File

@ -296,11 +296,7 @@ static void wm_notifier_clear(wmNotifier *note)
memset(((char *)note) + sizeof(Link), 0, sizeof(*note) - sizeof(Link));
}
/**
* Was part of #wm_event_do_notifiers, split out so it can be called once before entering the #WM_main loop.
* This ensures operators don't run before the UI and depsgraph are initialized.
*/
void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
void wm_event_do_depsgraph(bContext *C)
{
wmWindowManager *wm = CTX_wm_manager(C);
uint64_t win_combine_v3d_datamask = 0;
@ -315,18 +311,8 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
/* cached: editor refresh callbacks now, they get context */
for (wmWindow *win = wm->windows.first; win; win = win->next) {
const bScreen *screen = WM_window_get_active_screen(win);
Scene *scene = WM_window_get_active_scene(win);
ViewLayer *view_layer = WM_window_get_active_view_layer(win);
ScrArea *sa;
CTX_wm_window_set(C, win);
for (sa = screen->areabase.first; sa; sa = sa->next) {
if (sa->do_refresh) {
CTX_wm_area_set(C, sa);
ED_area_do_refresh(C, sa);
}
}
/* XXX make lock in future, or separated derivedmesh users in scene */
if (G.is_rendering == false) {
@ -350,6 +336,30 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
BKE_scene_graph_update_tagged(depsgraph, bmain);
}
}
}
/**
* Was part of #wm_event_do_notifiers, split out so it can be called once before entering the #WM_main loop.
* This ensures operators don't run before the UI and depsgraph are initialized.
*/
void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
{
wmWindowManager *wm = CTX_wm_manager(C);
/* cached: editor refresh callbacks now, they get context */
for (wmWindow *win = wm->windows.first; win; win = win->next) {
const bScreen *screen = WM_window_get_active_screen(win);
ScrArea *sa;
CTX_wm_window_set(C, win);
for (sa = screen->areabase.first; sa; sa = sa->next) {
if (sa->do_refresh) {
CTX_wm_area_set(C, sa);
ED_area_do_refresh(C, sa);
}
}
}
wm_event_do_depsgraph(C);
CTX_wm_window_set(C, NULL);
}

View File

@ -482,10 +482,11 @@ static void wm_file_read_post(bContext *C, const bool is_startup_file, const boo
CTX_wm_window_set(C, wm->windows.first);
ED_editors_init(C);
Main *bmain = CTX_data_main(C);
DEG_on_visible_update(bmain, true);
wm_event_do_depsgraph(C);
ED_editors_init(C);
#ifdef WITH_PYTHON
if (is_startup_file) {

View File

@ -97,6 +97,7 @@ void wm_event_do_handlers (bContext *C);
void wm_event_add_ghostevent (wmWindowManager *wm, wmWindow *win, int type, int time, void *customdata);
void wm_event_do_depsgraph(bContext *C);
void wm_event_do_refresh_wm_and_depsgraph(bContext *C);
void wm_event_do_notifiers(bContext *C);