mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-11 03:57:39 +00:00
Fix/impl refactor (#14776)
* fix: impl refactor * fix: unload/load python module, race conditions, freezes * remove dead code * remove extra hook * remove more dead code * fix gil run script
This commit is contained in:
@@ -105,7 +105,10 @@ struct GilSafeCallable
|
||||
{
|
||||
if (fn) {
|
||||
PythonGILState gil;
|
||||
fn = py::object();
|
||||
if (gil)
|
||||
fn = py::object();
|
||||
else
|
||||
(void) fn.release();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -127,6 +130,8 @@ GUI::PluginWebDialog::MessageHandler make_message_adapter(py::object on_message)
|
||||
return nullptr;
|
||||
return [holder](const json& data) {
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return;
|
||||
try {
|
||||
holder->fn(json_to_py(data));
|
||||
} catch (py::error_already_set& e) {
|
||||
@@ -343,6 +348,8 @@ py::object ui_create_window(const std::string& html, const std::string& title, i
|
||||
if (close_holder) {
|
||||
on_close = [close_holder]() {
|
||||
PythonGILState gil;
|
||||
if (!gil)
|
||||
return;
|
||||
try {
|
||||
close_holder->fn();
|
||||
} catch (py::error_already_set& e) {
|
||||
@@ -412,7 +419,7 @@ UiProgressHandle* new_progress_dialog(const std::string& title, const std::strin
|
||||
|
||||
bool progress_is_open(int id)
|
||||
{
|
||||
return UiRegistry::instance().get_as<GUI::PluginProgressDialog>(id) != nullptr;
|
||||
return UiRegistry::instance().is_open(id);
|
||||
}
|
||||
|
||||
bool progress_pulse(int id, const std::string& message)
|
||||
@@ -462,7 +469,10 @@ void PluginHostUi::RegisterBindings(pybind11::module_& host)
|
||||
auto ui = host.def_submodule(
|
||||
"ui",
|
||||
"Host UI: native dialogs and interactive HTML windows. Calls run on the main/UI "
|
||||
"thread (marshaled from the plugin thread). See the plugin docs for the window.orca bridge.");
|
||||
"thread (marshaled from the plugin thread). See the plugin docs for the window.orca bridge. "
|
||||
"Do not call these from a slicing pipeline hook (SlicingPipeline capability): that hook runs "
|
||||
"on the slicing worker thread, which the UI thread can itself be blocked waiting on, so a "
|
||||
"marshaled UI call from there can deadlock the application.");
|
||||
|
||||
ui.def("message", &ui_message, py::arg("text"), py::arg("title") = "OrcaSlicer", py::arg("buttons") = "ok",
|
||||
py::arg("icon") = "info",
|
||||
|
||||
@@ -9,15 +9,18 @@ namespace Slic3r {
|
||||
// Binds the `orca.host.ui` submodule: native message boxes, progress dialogs,
|
||||
// and interactive HTML windows for plugins. All calls run on the main/UI thread
|
||||
// (marshaled from the plugin worker thread) and the host owns every window.
|
||||
//
|
||||
// Not safe to call from a slicing pipeline hook (SlicingPipelinePluginCapability):
|
||||
// that hook runs on the slicing worker thread, which the UI thread can itself be
|
||||
// blocked waiting on, so marshaling a UI call from there can deadlock. Plugin
|
||||
// authors must not call orca.host.ui.* from pipeline hooks.
|
||||
class PluginHostUi
|
||||
{
|
||||
public:
|
||||
static void RegisterBindings(pybind11::module_& host);
|
||||
|
||||
// Lifecycle hook: close and tear down every UI window owned by a plugin.
|
||||
// Registered via PluginLoader::subscribe_on_unload_callback so UI windows
|
||||
// are destroyed on plugin unload/reload and at app shutdown (before the
|
||||
// Python interpreter is finalized). Matches PluginLifecycleCompleteFn.
|
||||
// Lifecycle hook: close and tear down every UI window owned by a plugin. PluginManager invokes
|
||||
// this after plugin teardown and also for bulk unload during application shutdown.
|
||||
static void close_windows_for_plugin(const std::string& plugin_key);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user