Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ruisapp/glue/windows/application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ application_glue::application_glue(const utki::version_duplet& gl_version) :
this->common_render_objects
)
),
#ifndef RUISAPP_RENDER_VULKAN
shared_gl_context_restorer(this->shared_gl_context_native_window.get()),
#endif
ruis_style_provider( //
utki::make_shared<ruis::style_provider>(this->ruis_resource_loader)
)
Expand Down
36 changes: 36 additions & 0 deletions src/ruisapp/glue/windows/application.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ public:
*/
void update_units_from_system();
};

/**
* @brief Re-binds the shared GL context on destruction.
*
* Rendering makes each window's GL context current, and the window contexts
* are destroyed together with the windows. After that, no GL context is
* current on this thread. The shared GL objects (common shaders, common
* render objects, shared resource textures) are destroyed after the windows
* and still need a current context of the shared group to be released, so
* this guard restores the shared context (which outlives the shared objects)
* right before they are destroyed.
*/
class restore_shared_gl_context_on_destruction
{
native_window& shared_gl_context_window;

public:
explicit restore_shared_gl_context_on_destruction(native_window& shared_gl_context_window) :
shared_gl_context_window(shared_gl_context_window)
{}

restore_shared_gl_context_on_destruction(const restore_shared_gl_context_on_destruction&) = delete;
restore_shared_gl_context_on_destruction& operator=(const restore_shared_gl_context_on_destruction&) = delete;

~restore_shared_gl_context_on_destruction()
{
this->shared_gl_context_window.bind_rendering_context();
}
};
} // namespace

namespace {
Expand Down Expand Up @@ -118,6 +147,13 @@ class application_glue : public utki::destructable
const utki::shared_ref<const ruis::render::renderer::objects> common_render_objects;
const utki::shared_ref<ruis::resource_loader> ruis_resource_loader;

#ifndef RUISAPP_RENDER_VULKAN
// Must be declared after common_render_objects (and thus destroyed
// before it), so that the shared GL context is re-bound before the
// shared GL objects are destroyed.
const restore_shared_gl_context_on_destruction shared_gl_context_restorer;
Comment thread
igagis marked this conversation as resolved.
Resolved
#endif

public:
const utki::shared_ref<ruis::style_provider> ruis_style_provider;

Expand Down
Loading