Files
EVEngine/src/engine/devtools/Immortal.hpp
T
西风逍遥游 f62261a779 fix(engine): validate Runtime stack size before VM creation; centralize DevTools singletons
Runtime now validates stackSize before constructing the Squirrel VM (previously the check ran after member initialization). DevTools singletons (AiPanel/ConsolePanel/McpServer/RenderVision) keep their process-immortal lifetime - required by the detached stdio reader thread and cross-singleton calls - but move from scattered raw new leaks to a single documented Immortal holder.
2026-08-19 22:44:52 +08:00

34 lines
1.1 KiB
C++

#pragma once
namespace eve::dev {
/**
* @brief Process-immortal singleton holder for DevTools objects.
*
* AiPanel / ConsolePanel / McpServer / RenderVision are deliberately never
* destroyed: McpServer's stdio reader thread can outlive normal teardown (it
* is detached when reading from stdin), and the singletons call into each
* other from request handling. Destroying any of them could let that thread
* lock a destroyed mutex (macOS libc++ aborts). This holder makes the
* immortal-lifetime contract explicit and centralized instead of scattering
* raw `new` leaks through every accessor.
*
* @tparam T Singleton type; constructed on first get(), never destroyed.
*/
template <typename T>
struct Immortal {
/** @brief Returns the process-lifetime instance. */
static T& get() {
static Immortal holder; // function-local static: constructed once
return *holder.value;
}
Immortal() : value(new T()) {}
Immortal(const Immortal&) = delete;
Immortal& operator=(const Immortal&) = delete;
T* value;
};
} // namespace eve::dev