修复程序退出时访问NoticeCenter单例可能崩溃的bug

This commit is contained in:
xiongziliang
2026-07-08 10:56:53 +08:00
parent 6c0bc2e5c0
commit a485d89063
2 changed files with 6 additions and 1 deletions

View File

@@ -623,10 +623,11 @@ PythonInvoker::PythonInvoker() {
}
}
});
_notice_center = NoticeCenter::Instance().shared_from_this();
}
PythonInvoker::~PythonInvoker() {
NoticeCenter::Instance().delListener(this, Broadcast::kBroadcastReloadConfig);
_notice_center->delListener(this, Broadcast::kBroadcastReloadConfig);
{
py::gil_scoped_acquire gil; // 加锁
if (_on_exit) {

View File

@@ -8,6 +8,9 @@
#include <string>
#include <pybind11/embed.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h> // ⭐ 必须
#include <pybind11/functional.h> // ⭐ 必须
#include <pybind11/numpy.h>
#include "Util/logger.h"
#include "Common/config.h"
#include "Common/MediaSource.h"
@@ -46,6 +49,7 @@ private:
PythonInvoker();
private:
toolkit::NoticeCenter::Ptr _notice_center;
py::gil_scoped_release *_rel;
py::scoped_interpreter *_interpreter;
std::shared_ptr<toolkit::Logger> _logger;