简体   繁体   English

导入.obj时出现Assimp未处理的异常

[英]Assimp Unhandled Exception when importing .obj

I've been trying to get Assimp to work correctly for the past two weeks, to no avail, so I decided asking here was the best thing to do. 在过去的两周里,我一直在努力使Assimp正常工作,但无济于事,所以我决定问这是最好的方法。 I followed thecplusplusguy's tutorial on importing static meshes, and I've copied it word for word in an effort to get it to work. 我遵循了cplusplusguy的有关导入静态网格物体的教程,并且为了使它正常工作,已经逐词复制了它。

When I try to import an .obj (a cube, if that matters) it says I have an "Unhandled exception at 0x00EF061B in OpenGL.exe: 0xC0000005: Access violation reading location 0xABABAFFB" , it stops the program and tells me it's on line 30 of my code ( "for(int i=0; imNumMeshes; i++)" ). 当我尝试导入.obj(多维数据集,如果那很重要)时,它说我有一个“ OpenGL.exe中0x00EF061B的未处理异常:0xC0000005:访问冲突读取位置0xABABAFFB” ,它停止程序并告诉我它在线我的代码中的30( “ for(int i = 0; imNumMeshes; i ++)” )。

#include "sceneloader.h"

sceneLoader::sceneLoader(){
    std::cout<<"New scene created."<<std::endl;
}

sceneLoader::sceneLoader(const char* filename){
    std::cout<<"Scene loading hath begun."<<std::endl;
    Assimp::Importer importer;
    const aiScene* scene = importer.ReadFile(filename,aiProcess_GenSmoothNormals | aiProcess_Triangulate |
        aiProcess_CalcTangentSpace | aiProcess_FlipUVs |
        aiProcess_JoinIdenticalVertices);

    if(scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE){
        std::cout<<"MFLAGS - Scene '"<<filename<<"' could not be loaded."<<std::endl;
        return;
    }
    if(!scene->mRootNode){
        std::cout<<"MROOTNODE - Scene '"<<filename<<"' could not be loaded."<<std::endl;
        return;
    }
    std::cout<<"Recursive processing about to begin."<<std::endl;

    recursiveProcess(scene->mRootNode,scene);
    std::cout<<"Recursive processing finished."<<std::endl;
}

void sceneLoader::recursiveProcess(aiNode* node, const aiScene* scene){
    //process
    for(int i = 0; i<node->mNumMeshes;i++){         //HERE IS THE PROBLEM
        aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
            processMesh(mesh,scene);
        }
        //recursion
        for(int i = 0; 0<node->mNumChildren;i++){
            recursiveProcess(node->mChildren[i],scene);
        }
}

When I've added couts to debug it, the "scene->mNumMeshes" returns 1 (which it should, since it's one cube), but "node->mNumMeshes" returns 0. 当我添加了调试信息后,“ scene-> mNumMeshes”返回1(由于是一个立方体,因此应该返回1),但是“ node-> mNumMeshes”返回0。

I understand that an unhandled exception occurs when there's a null pointer, and that the null pointer here is the "node->mNumMeshes", but why is it null? 我了解到,当存在空指针时会发生未处理的异常,并且此处的空指针为“ node-> mNumMeshes”,但是为什么它为空? And how would I fix this? 我该如何解决?

My bad. 我的错。 There was a typo: 有一个错字:

void sceneLoader::recursiveProcess(aiNode* node, const aiScene* scene){
    //process
    for(int i = 0; i<node->mNumMeshes;i++){         
        aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
            processMesh(mesh,scene);
        }
        //recursion
        for(int i = 0; 0<node->mNumChildren;i++){ //IT SHOULD BE AN i INSTEAD OF A ZERO
            recursiveProcess(node->mChildren[i],scene);
        }
}

Finished code looks like this: 完成的代码如下所示:

void sceneLoader::recursiveProcess(aiNode* node, const aiScene* scene){
    //process

    for(unsigned int i = 0; i<node->mNumMeshes;i++){    
        aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
        processMesh(mesh,scene);
        }
        //recursion
    if(node->mNumChildren > 0){
            for(unsigned int i = 0; i<node->mNumChildren;i++){
                recursiveProcess(node->mChildren[i],scene);
            }
    }
}

Sorry. 抱歉。 Won't happen again. 不会再发生了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM