diff options
author | William Leeson <leesonw> | 2021-10-13 12:08:11 +0300 |
---|---|---|
committer | William Leeson <william@blender.org> | 2021-10-13 12:09:22 +0300 |
commit | 3021babf38f88a7e8099189ffa84addf84430dfe (patch) | |
tree | dd794fd5ff3a24c237e492582450a3676271abf5 /intern/cycles/blender/blender_session.cpp | |
parent | 53af51ad50ec43ee960eb9125f0adf5c37e2a5cd (diff) |
Fix: Stops assert when baking in debug mode.
When baking in a debug build running gdb it kept asserting because a GL context was being created outside the main thread.
To fix this the patch only creates the GL context is only created for rendering (when it is actually used).
Reviewed By: sergey
Differential Revision: https://developer.blender.org/D12767
Diffstat (limited to 'intern/cycles/blender/blender_session.cpp')
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 0bee265557f..38dbb6ab8b1 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -158,15 +158,6 @@ void BlenderSession::create_session() b_v3d, b_rv3d, scene->camera, width, height); session->reset(session_params, buffer_params); - /* Create GPU display. - * TODO(sergey): Investigate whether DisplayDriver can be used for the preview as well. */ - if (!b_engine.is_preview() && !headless) { - unique_ptr<BlenderDisplayDriver> display_driver = make_unique<BlenderDisplayDriver>(b_engine, - b_scene); - display_driver_ = display_driver.get(); - session->set_display_driver(move(display_driver)); - } - /* Viewport and preview (as in, material preview) does not do tiled rendering, so can inform * engine that no tracking of the tiles state is needed. * The offline rendering will make a decision when tile is being written. The penalty of asking @@ -355,6 +346,7 @@ void BlenderSession::render(BL::Depsgraph &b_depsgraph_) } /* Create driver to write out render results. */ + ensure_display_driver_if_needed(); session->set_output_driver(make_unique<BlenderOutputDriver>(b_engine)); session->full_buffer_written_cb = [&](string_view filename) { full_buffer_written(filename); }; @@ -727,6 +719,8 @@ void BlenderSession::synchronize(BL::Depsgraph &b_depsgraph_) /* unlock */ session->scene->mutex.unlock(); + ensure_display_driver_if_needed(); + /* Start rendering thread, if it's not running already. Do this * after all scene data has been synced at least once. */ session->start(); @@ -763,8 +757,10 @@ void BlenderSession::draw(BL::SpaceImageEditor &space_image) draw_state_.last_pass_index = pass_index; } - BL::Array<float, 2> zoom = space_image.zoom(); - display_driver_->set_zoom(zoom[0], zoom[1]); + if (display_driver_) { + BL::Array<float, 2> zoom = space_image.zoom(); + display_driver_->set_zoom(zoom[0], zoom[1]); + } session->draw(); } @@ -979,4 +975,27 @@ void BlenderSession::free_blender_memory_if_possible() b_engine.free_blender_memory(); } +void BlenderSession::ensure_display_driver_if_needed() +{ + if (display_driver_) { + /* Driver is already created. */ + return; + } + + if (headless) { + /* No display needed for headless. */ + return; + } + + if (b_engine.is_preview()) { + /* TODO(sergey): Investigate whether DisplayDriver can be used for the preview as well. */ + return; + } + + unique_ptr<BlenderDisplayDriver> display_driver = make_unique<BlenderDisplayDriver>(b_engine, + b_scene); + display_driver_ = display_driver.get(); + session->set_display_driver(move(display_driver)); +} + CCL_NAMESPACE_END |