我一直试图让Assimp在过去两周内正常工作,但无济于事,所以我决定在这里问最好的事情 . 我遵循了关于导入静态网格物体的cplusplusguy的教程,并且我已经逐字逐句地复制它以使其工作 .
当我尝试导入.obj(一个多维数据集,如果这很重要)它说我有 "Unhandled exception at 0x00EF061B in OpenGL.exe: 0xC0000005: Access violation reading location 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);
}
}
当我添加couts来调试它时,“scene-> mNumMeshes”返回1(它应该是,因为它是一个立方体),但是“node-> mNumMeshes”返回0 .
我知道当有一个空指针时会发生未处理的异常,并且这里的空指针是“node-> mNumMeshes”,但为什么它为null?我该如何解决这个问题?
1 回答
我的错 . 有一个错字:
完成的代码如下所示:
抱歉 . 不会再发生了 .