Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr

目录

[jni ncnn 推理报错:](#jni ncnn 推理报错:)

[Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr](#Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr)


jni ncnn 推理报错:

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr

代码调用正常,所以是析构时报错,解决方法:

jni/cls_mobilenet.cpp

cpp 复制代码
MobileNetInference::~MobileNetInference() {
    net_.clear(); // <-- 必须先 clear
    #if NCNN_VULKAN
        ncnn::destroy_gpu_instance();
    #endif
}

// 加载模型
bool MobileNetInference::load_model(AAssetManager* mgr,const std::string& param_path,
                                    const std::string& bin_path) {

    ncnn::set_cpu_powersave(2);
    net_.opt = ncnn::Option();

#if NCNN_VULKAN
    if (use_gpu_) {
        // 创建 GPU 实例 --- 注意:最好在全局只创建一次(这里示例化创建)
        ncnn::create_gpu_instance();
        net_.opt.use_vulkan_compute = true;
    } else {
        net_.opt.use_vulkan_compute = false;
    }
#endif

    // 使用你设置的线程数而不是 get_big_cpu_count()(或至少赋值)
    net_.opt.num_threads = num_threads_;

    net_.opt.num_threads = ncnn::get_big_cpu_count();

    // 1. 加载参数文件
    int ret = net_.load_param(mgr, param_path.c_str());
    if (ret != 0) {
        return false;
    }

    // 2. 加载模型权重
    ret = net_.load_model(mgr, bin_path.c_str());
    if (ret != 0) {
        return false;
    }

    model_loaded_ = true;

    const std::vector<const char*>& input_names = net_.input_names();
    const std::vector<const char*>& output_names = net_.output_names();

    std::cout << "Input names: ";
    for (auto name : input_names) {
        std::cout << name << " ";
    }

    std::cout << "Output names: ";
    for (auto name : output_names) {
        std::cout << name << " ";
    }

    std::cout << "Model loaded successfully from:" << std::endl;
    std::cout << "  - " << param_path << std::endl;
    std::cout << "  - " << bin_path << std::endl;
    std::cout << "Using " << (use_gpu_ ? "GPU (Vulkan)" : "CPU")
              << " with " << num_threads_ << " threads." << std::endl;

    return true;
}
相关推荐
cmpxr_6 分钟前
【C】局部变量和全局变量及同名情况
c语言·开发语言
hetao173383732 分钟前
2026-04-09~12 hetao1733837 的刷题记录
c++·算法
6Hzlia33 分钟前
【Hot 100 刷题计划】 LeetCode 136. 只出现一次的数字 | C++ 哈希表&异或基础解法
c++·算法·leetcode
小碗羊肉43 分钟前
【从零开始学Java | 第三十一篇下】Stream流
java·开发语言
MWWZ1 小时前
最近的一些软件更新
opencv·算法·计算机视觉
CoovallyAIHub1 小时前
视频理解新范式:Agent不再被动看视频,LensWalk让它自己决定看哪里
算法·架构·github
汉克老师1 小时前
GESP2024年6月认证C++三级( 第二部分判断题(1-10))
c++·数组·位运算·补码·gesp三级·gesp3级
CoovallyAIHub1 小时前
斯坦福丨AirVLA:将地面机械臂模型迁移至无人机实现空中抓取,成功率从23%提升至50%
算法·架构·github
aq55356001 小时前
Laravel10.x重磅升级,新特性一览
android·java·开发语言
报错小能手2 小时前
ios开发方向——swift错误处理:do/try/catch、Result、throws
开发语言·学习·ios·swift