This commit is contained in:
wangjiyu 2025-04-10 18:31:30 +08:00
parent eb8c8ba8f5
commit 18b4bc00b2
1 changed files with 15 additions and 7 deletions

View File

@ -57,14 +57,22 @@ public:
return instance;
}
static void** numpy_api() {
void** ptr = reinterpret_cast<void**>(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<void**>(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;