3

我正在尝试使用用 VS2008 构建的 Assimp 加载 3D 对象。Assimp 示例代码正确加载对象,直到我定义(但不实例化)一个网格类来处理我的构建中的对象数据。具体来说,当我包含检查向量大小的代码时会发生错误。无论我是否使用 Assimp 的 noboost 版本,都会出现此问题。我尝试了几个不同的 .obj 文件,结果相同。

使用调试器,我发现 Assimp 加载程序在读取 .obj 文件的面时失败。这发生在 Assimp 的 ObjFileParser.cpp 的第 317 行:

pIndices->push_back( iVal-1 );

Mesh.cpp(该类未实例化或用作 main.cpp 中的预声明)

#pragma once

#include <vector>

class Mesh
{
    void Init(const std::vector<unsigned int>& Indices){  Indices.size(); }
                                                          ^^^^^^^^^^^^^^^
};

主文件

#include <assimp/Importer.hpp> // C++ importer interface
#include <assimp/scene.h> // Output data structure
#include <assimp/postprocess.h> // Post processing flags
bool DoTheImportThing( const std::string& pFile)
{
    // Create an instance of the Importer class
    Assimp::Importer importer;
    // And have it read the given file with some example postprocessing
    // Usually - if speed is not the most important aspect for you - you'll
    // propably to request more postprocessing than we do in this example.
    const aiScene* scene = importer.ReadFile( pFile,
        aiProcess_CalcTangentSpace |
        aiProcess_Triangulate |
        aiProcess_JoinIdenticalVertices |
        aiProcess_SortByPType);
    // If the import failed, report it
    if( !scene)
    {
        //DoTheErrorLogging( importer.GetErrorString());
        const char* err =  importer.GetErrorString();
        return false;
    }
    // Now we can access the file's contents.
    //DoTheSceneProcessing( scene);
    // We're done. Everything will be cleaned up by the importer destructor
    return true;
}


int main()

{
    DoTheImportThing("floor.obj");

}

在 mlock.c 中抛出内存位置异常的 std::bad_alloc

void __cdecl _unlock (
        int locknum
        )
{
        /*
         * leave the critical section.
         */
        LeaveCriticalSection( _locktable[locknum].lock );
}

我的调用堆栈是

    KernelBase.dll!7512c41f()   
    [Frames below may be incorrect and/or missing, no symbols loaded for KernelBase.dll]    
    KernelBase.dll!7512c41f()   
    ntdll.dll!7746107b()    
>   msvcr90d.dll!_unlock(int locknum=8)  Line 376   C
    msvcr90d.dll!_unlockexit()  Line 808 + 0x7 bytes    C
    msvcr90d.dll!_CxxThrowException(void * pExceptionObject=0x0110d644, const _s__ThrowInfo * pThrowInfo=0x54655f68)  Line 161  C++
    msvcr90d.dll!operator new(unsigned int size=842150452)  Line 64 C++
    AssimpLoadFileTest.exe!std::_Allocate<unsigned int>(unsigned int _Count=210537613, unsigned int * __formal=0x00000000)  Line 43 + 0xc bytes C++
    AssimpLoadFileTest.exe!std::allocator<unsigned int>::allocate(unsigned int _Count=210537613)  Line 145 + 0xb bytes  C++
    AssimpLoadFileTest.exe!std::vector<unsigned int,std::allocator<unsigned int> >::_Insert_n(std::_Vector_const_iterator<unsigned int,std::allocator<unsigned int> > _Where=..., unsigned int _Count=1, const unsigned int & _Val=0)  Line 1173 + 0xf bytes    C++
    AssimpLoadFileTest.exe!std::vector<unsigned int,std::allocator<unsigned int> >::insert(std::_Vector_const_iterator<unsigned int,std::allocator<unsigned int> > _Where=..., const unsigned int & _Val=0)  Line 878   C++
    AssimpLoadFileTest.exe!std::vector<unsigned int,std::allocator<unsigned int> >::push_back(const unsigned int & _Val=0)  Line 824    C++
    AssimpLoadFileTest.exe!Assimp::ObjFileParser::getFace(aiPrimitiveType type=aiPrimitiveType_POLYGON)  Line 319 + 0x1e bytes  C++
    AssimpLoadFileTest.exe!Assimp::ObjFileParser::parseFile()  Line 142 C++
    AssimpLoadFileTest.exe!Assimp::ObjFileParser::ObjFileParser(std::vector<char,std::allocator<char> > & Data=[216](103 'g',32 ' ',102 'f',108 'l',111 'o',111 'o',114 'r',13 '
',10 '
',118 'v',32 ' ',45 '-',53 '5',48 '0',48 '0',46 '.',48 '0',32 ' ',48 '0',46 '.',48 '0',32 ' ',45 '-',53 '5',48 '0',48 '0',46 '.',48 '0',13 '
',10 '
',118 'v',32 ' ',45 '-',53 '5',48 '0',48 '0',46 '.',48 '0',32 ' ',48 '0',46 '.',48 '0',32 ' ',53 '5',48 '0',48 '0',46 '.',48 '0',13 '
',10 '
',118 'v',32 ' ',53 '5',48 '0',48 '0',...,...), const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & strModelName="floor.obj", Assimp::IOSystem * io=0x0110f464)  Line 81   C++
    AssimpLoadFileTest.exe!Assimp::ObjFileImporter::InternReadFile(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & pFile="floor.obj", aiScene * pScene=0x00e7a738, Assimp::IOSystem * pIOHandler=0x0110f464)  Line 145 + 0x1d bytes    C++
    AssimpLoadFileTest.exe!Assimp::BaseImporter::ReadFile(const Assimp::Importer * pImp=0x0110faac, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & pFile="floor.obj", Assimp::IOSystem * pIOHandler=0x00e72e88)  Line 88 + 0x2c bytes C++
    AssimpLoadFileTest.exe!Assimp::Importer::ReadFile(const char * _pFile=0x0110fae8, unsigned int pFlags=32779)  Line 650 + 0x18 bytes C++
    AssimpLoadFileTest.exe!Assimp::Importer::ReadFile(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & pFile="floor.obj", unsigned int pFlags=32779)  Line 629  C++
    AssimpLoadFileTest.exe!DoTheImportThing(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & pFile="floor.obj")  Line 15 + 0x11 bytes   C++
    AssimpLoadFileTest.exe!main()  Line 34 + 0x2d bytes C++
    AssimpLoadFileTest.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes   C
    AssimpLoadFileTest.exe!mainCRTStartup()  Line 403   C
    kernel32.dll!75a1336a()     
    ntdll.dll!77459f72()    
    ntdll.dll!77459f45()    

输出:

'AssimpLoadFileTest.exe': Loaded 'C:\Visual Studio 2008\Projects\AssimpLoadFileTest\Debug\AssimpLoadFileTest.exe', Symbols loaded.
'AssimpLoadFileTest.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll'
'AssimpLoadFileTest.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll'
'AssimpLoadFileTest.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll'
'AssimpLoadFileTest.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_2a4f639a55563668\msvcp90d.dll', Symbols loaded.
'AssimpLoadFileTest.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_2a4f639a55563668\msvcr90d.dll', Symbols loaded.
First-chance exception at 0x7512c41f in AssimpLoadFileTest.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0110d644..
The program '[3340] AssimpLoadFileTest.exe: Native' has exited with code 0 (0x0).

地板.obj:

g floor
v -500.0 0.0 -500.0
v -500.0 0.0 500.0
v 500.0 0.0 -500.0
v 500.0 0.0 500.0
#
vn 0 1 0
#
vt 0.0 0.0
vt 0.0 500.0
vt 500.0 0.0
vt 500.0 500.0
#
f 1/1/1 2/2/1 3/3/1 
f 3/3/1 2/2/1 4/4/1                             
4

0 回答 0