From 17f31ea3e06d1ca76cd692d98261d18e8e1c7267 Mon Sep 17 00:00:00 2001 From: faumaray Date: Mon, 22 Jun 2026 21:47:17 +0300 Subject: [PATCH] Plugin adapter: self-initialize so Void reload protocol works end-to-end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Void::Plugin::PluginLoader::reload() transfers state (deserialize_state) before on_load(), on a freshly-created instance — but Core's restoreAfterHotReload needs an initialized Core. Make the adapter self-initialize from the default config path in both on_load() (first load / post-swap) and deserialize_state (during transfer), guarded by isInitialized() so it is idempotent. This resolves the init-before-restore ordering and lets the host migrate to PluginManager as plain wiring. The legacy CreateCore path is unaffected (on_load is only reached through the void_plugin_* C ABI). Live hot-reload state-survival under TeamSpeak remains the runtime gate. Co-Authored-By: Claude Opus 4.8 --- src/Export.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Export.cpp b/src/Export.cpp index c61668b..49a6afd 100644 --- a/src/Export.cpp +++ b/src/Export.cpp @@ -36,6 +36,17 @@ namespace Echoion::Core { return "Echoion"; } + + // Void::Plugin::PluginLoader calls on_load() once after create + // (first load and after a reload swap). Self-initialize from the + // default config path so the plugin is ready without host-provided + // wiring; idempotent via isInitialized(). + void on_load() override + { + if (!isInitialized()) { + (void)initialize(ConfigLoader::getDefaultConfigPath()); + } + } }; } // namespace Echoion::Core @@ -103,6 +114,16 @@ extern "C" if (!core || !json) { return -1; } + // reload() transfers state before on_load(), so the freshly-created + // instance is not yet initialized — bring it up first, then restore. + // Idempotent: a no-op once initialized. + if (!core->isInitialized()) { + auto initResult = + core->initialize(Echoion::Core::ConfigLoader::getDefaultConfigPath()); + if (!initResult) { + return -1; + } + } auto result = core->restoreAfterHotReload(std::string(json)); return result ? 0 : -1; }