From 30cd1f8d1ebc0894831e59c7690f6b60988f9f25 Mon Sep 17 00:00:00 2001 From: igagis-bot Date: Thu, 26 Nov 2026 16:57:44 +0200 Subject: [PATCH] windows: fix post_to_ui_thread() posting to the calling thread's queue --- src/ruisapp/glue/windows/application.cxx | 12 ++++++++---- src/ruisapp/glue/windows/application.hxx | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ruisapp/glue/windows/application.cxx b/src/ruisapp/glue/windows/application.cxx index 4d7f372..2c8c8a4 100644 --- a/src/ruisapp/glue/windows/application.cxx +++ b/src/ruisapp/glue/windows/application.cxx @@ -145,7 +145,11 @@ application_glue::application_glue(const utki::version_duplet& gl_version) : ), ruis_style_provider( // utki::make_shared(this->ruis_resource_loader) - ) + ), + // the glue is created on the UI thread (the thread running the main loop); + // post_to_ui_thread() uses this id to post procedures to the UI thread's + // message queue + ui_thread_id(::GetCurrentThreadId()) {} void application_glue::render() @@ -158,15 +162,15 @@ void application_glue::render() void application_glue::post_to_ui_thread(std::function procedure) { if ( // - PostMessage( // - NULL, // post message to UI thread's message queue + PostThreadMessage( // + this->ui_thread_id, // post message to the UI thread's message queue WM_USER, 0, // no wParam // NOLINTNEXTLINE(cppcoreguidelines-owning-memory, cppcoreguidelines-pro-type-reinterpret-cast) reinterpret_cast(new std::function(std::move(procedure))) ) == 0) { - throw std::runtime_error("PostMessage(): failed"); + throw std::runtime_error("PostThreadMessage(): failed"); } } diff --git a/src/ruisapp/glue/windows/application.hxx b/src/ruisapp/glue/windows/application.hxx index 9f55ca1..e4d6596 100644 --- a/src/ruisapp/glue/windows/application.hxx +++ b/src/ruisapp/glue/windows/application.hxx @@ -131,6 +131,11 @@ private: public: std::atomic_bool quit_flag = false; + // the id of the UI thread (the thread that created the glue and runs the + // main loop); post_to_ui_thread() uses it to post procedures to the UI + // thread's message queue + const DWORD ui_thread_id; + const utki::shared_ref updater = utki::make_shared(); std::vector> windows_to_destroy;