From 18b4bc00b23f5cdb0cc6184159ddcba3c46b06e9 Mon Sep 17 00:00:00 2001 From: wangjiyu Date: Thu, 10 Apr 2025 18:31:30 +0800 Subject: [PATCH] debug --- util/RTCContext.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/util/RTCContext.h b/util/RTCContext.h index 51b6689..c5a9930 100644 --- a/util/RTCContext.h +++ b/util/RTCContext.h @@ -57,14 +57,22 @@ public: return instance; } static void** numpy_api() { - void** ptr = reinterpret_cast(RTC_PLUGINS_ARRAY_API); + static void** api = [](){ + // 强制初始化NumPy + if (_import_array() < 0) { + PyErr_Print(); + throw std::runtime_error("NumPy initialization failed"); + } - // 深度验证API有效性 - if (!ptr || !ptr[93]) { // 93是PyArray_SimpleNew的偏移量 - PyErr_Print(); - throw std::runtime_error("Invalid NumPy API structure"); - } - return ptr; + void** ptr = reinterpret_cast(RTC_PLUGINS_ARRAY_API); + if (!ptr || !ptr[93]) { + std::cerr << "NumPy API corrupt! Expected at 93: " + << (ptr ? (void*)ptr[93] : nullptr) << std::endl; + abort(); + } + return ptr; + }(); + return api; } RTCContext(const RTCContext&) = delete; RTCContext& operator=(const RTCContext&) = delete;