From a9362449a6d41cbc9023b8b38355a66d7703e51d Mon Sep 17 00:00:00 2001 From: wangjiyu Date: Thu, 10 Apr 2025 10:40:38 +0800 Subject: [PATCH] debug --- rtc_plugins.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rtc_plugins.cpp b/rtc_plugins.cpp index 0558977..f8d2484 100644 --- a/rtc_plugins.cpp +++ b/rtc_plugins.cpp @@ -72,21 +72,23 @@ int sendCustomAudioData(int16_t destChannelIndex, py::object pD, throw std::runtime_error("Failed to convert input to int16 array"); } - // 修复点:显式构造 py::object(两种写法均可) - py::object arr(py::handle<>(py_array)); // 写法1:构造函数 - // py::object arr = py::reinterpret_borrow(py_array); // 写法2:borrow语义 + // 修复点:使用花括号初始化 + py::object arr{py::handle<>(py_array)}; // 检查数据长度 PyArrayObject* npArray = reinterpret_cast(arr.ptr()); if (PyArray_SIZE(npArray) != static_cast(dataLen)) { + Py_DECREF(py_array); throw std::runtime_error("Array length does not match dataLen"); } // 处理数据... void* dataPtr = PyArray_DATA(npArray); - return RTCContext::instance().sendCustomAudioData( + int ret = RTCContext::instance().sendCustomAudioData( destChannelIndex, dataPtr, sampleRate, channelNum, dataLen ); + Py_DECREF(py_array); // 释放临时数组 + return ret; } catch (...) { PyErr_SetString(PyExc_RuntimeError, "Invalid audio data"); return -1;