From 09677e362000c20b4c3a27e9b5889d929483b935 Mon Sep 17 00:00:00 2001 From: impressionyang Date: Wed, 13 May 2026 17:43:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20SenseVoiceEngine=20?= =?UTF-8?q?Windows=20=E7=BC=96=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Impl 的 QMutex 移出 HAVE_ONNXRUNTIME 条件编译块 - loadModelSync/loadModelAsync 中的 ONNX 成员访问添加 #ifdef 保护 Co-Authored-By: Claude Opus 4.6 --- src/core/sense_voice_engine.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/sense_voice_engine.cpp b/src/core/sense_voice_engine.cpp index a05ef12..7f28b85 100644 --- a/src/core/sense_voice_engine.cpp +++ b/src/core/sense_voice_engine.cpp @@ -184,9 +184,9 @@ struct SenseVoiceEngine::Impl { return false; } } +#endif QMutex mutex; -#endif }; SenseVoiceEngine::SenseVoiceEngine(QObject* parent) @@ -206,14 +206,17 @@ bool SenseVoiceEngine::loadModelSync(const QString& modelPath, if (loaded_) { LOG_WARNING(kTag, "模型已加载,先卸载再加载"); // 内联清理,避免调用 unloadModel() 导致 mutex 递归死锁 +#ifdef HAVE_ONNXRUNTIME impl_->session.reset(); impl_->sessionOptions.reset(); impl_->env.reset(); impl_->features.reset(); impl_->tokenizer = SenseVoiceTokenizer(); +#endif loaded_ = false; } +#ifdef HAVE_ONNXRUNTIME QString errorMsg; bool success = impl_->loadInWorker(modelPath, tokensPath, device, numThreads, errorMsg); loaded_ = success; @@ -225,6 +228,11 @@ bool SenseVoiceEngine::loadModelSync(const QString& modelPath, emit error(errorMsg); } return success; +#else + (void)modelPath; (void)tokensPath; (void)device; (void)numThreads; + LOG_ERROR(kTag, "ONNX Runtime 未编译启用"); + return false; +#endif } void SenseVoiceEngine::loadModelAsync(const QString& modelPath, @@ -235,14 +243,17 @@ void SenseVoiceEngine::loadModelAsync(const QString& modelPath, if (loaded_) { LOG_WARNING(kTag, "模型已加载,先卸载再加载"); // 内联清理,避免调用 unloadModel() 导致 mutex 递归死锁 +#ifdef HAVE_ONNXRUNTIME impl_->session.reset(); impl_->sessionOptions.reset(); impl_->env.reset(); impl_->features.reset(); impl_->tokenizer = SenseVoiceTokenizer(); +#endif loaded_ = false; } +#ifdef HAVE_ONNXRUNTIME LOG_INFO(kTag, QString("异步加载 SenseVoice 模型: %1").arg(modelPath)); QFuture future = QtConcurrent::run([this, modelPath, tokensPath, device, numThreads]() { @@ -259,6 +270,10 @@ void SenseVoiceEngine::loadModelAsync(const QString& modelPath, } }, Qt::QueuedConnection); }); +#else + (void)modelPath; (void)tokensPath; (void)device; (void)numThreads; + LOG_ERROR(kTag, "ONNX Runtime 未编译启用"); +#endif } void SenseVoiceEngine::unloadModel() {