diff --git a/util/RTCContext.h b/util/RTCContext.h index d93697c..51b6689 100644 --- a/util/RTCContext.h +++ b/util/RTCContext.h @@ -57,11 +57,14 @@ public: return instance; } static void** numpy_api() { - static void** api = [](){ - // 延迟获取实际指针 - return reinterpret_cast(RTC_PLUGINS_ARRAY_API); - }(); - return api; + void** ptr = reinterpret_cast(RTC_PLUGINS_ARRAY_API); + + // 深度验证API有效性 + if (!ptr || !ptr[93]) { // 93是PyArray_SimpleNew的偏移量 + PyErr_Print(); + throw std::runtime_error("Invalid NumPy API structure"); + } + return ptr; } RTCContext(const RTCContext&) = delete; RTCContext& operator=(const RTCContext&) = delete;