我一直试图让Assimp在过去两周内正常工作,但无济于事,所以我决定在这里问最好的事情。我遵循了关于导入静态网格物体的cplusplusguy教程,并且我已经逐字逐句地复制它,以便让它发挥作用。
当我尝试导入.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);
}
}
当我添加了couts进行调试时,&#34; scene-&gt; mNumMeshes&#34;返回1(它应该是,因为它是一个立方体),但是&#34; node-&gt; mNumMeshes&#34;返回0.
我理解当有一个空指针时会发生未处理的异常,并且这里的空指针是&#34; node-&gt; mNumMeshes&#34;,但为什么它为null?我该如何解决这个问题?
答案 0 :(得分:1)
我的坏。 有一个错字:
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);
}
}
完成的代码如下所示:
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);
}
}
}
对不起。 不会再发生。