Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::bad_alloc at memory location exception while loading a 3D object using Assimp
    primarykey
    data
    text
    <p>I'm trying to load 3D objects using Assimp built with VS2008. The Assimp example code loads the object correctly until I define (but don't instantiate) a mesh class to handle the object data in my build. <strong>Specifically, the error occurs when I include code to check the size of a vector.</strong> This problem occurs regardless of whether I use the noboost version of Assimp. I've tried several different .obj files with the same result.</p> <p>Using the debugger, I've found that the Assimp loader fails when reading the faces of an .obj file. This happens on line 317 of Assimp's ObjFileParser.cpp:</p> <pre><code>pIndices-&gt;push_back( iVal-1 ); </code></pre> <p>Mesh.cpp (this class is not instantiated or used as a predeclaration in main.cpp)</p> <pre><code>#pragma once #include &lt;vector&gt; class Mesh { void Init(const std::vector&lt;unsigned int&gt;&amp; Indices){ Indices.size(); } ^^^^^^^^^^^^^^^ }; </code></pre> <p>main.cpp</p> <pre><code>#include &lt;assimp/Importer.hpp&gt; // C++ importer interface #include &lt;assimp/scene.h&gt; // Output data structure #include &lt;assimp/postprocess.h&gt; // Post processing flags bool DoTheImportThing( const std::string&amp; 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"); } </code></pre> <p>The std::bad_alloc at memory location exception is thrown in mlock.c</p> <pre><code>void __cdecl _unlock ( int locknum ) { /* * leave the critical section. */ LeaveCriticalSection( _locktable[locknum].lock ); } </code></pre> <p>My call stack is </p> <pre><code> KernelBase.dll!7512c41f() [Frames below may be incorrect and/or missing, no symbols loaded for KernelBase.dll] KernelBase.dll!7512c41f() ntdll.dll!7746107b() &gt; 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&lt;unsigned int&gt;(unsigned int _Count=210537613, unsigned int * __formal=0x00000000) Line 43 + 0xc bytes C++ AssimpLoadFileTest.exe!std::allocator&lt;unsigned int&gt;::allocate(unsigned int _Count=210537613) Line 145 + 0xb bytes C++ AssimpLoadFileTest.exe!std::vector&lt;unsigned int,std::allocator&lt;unsigned int&gt; &gt;::_Insert_n(std::_Vector_const_iterator&lt;unsigned int,std::allocator&lt;unsigned int&gt; &gt; _Where=..., unsigned int _Count=1, const unsigned int &amp; _Val=0) Line 1173 + 0xf bytes C++ AssimpLoadFileTest.exe!std::vector&lt;unsigned int,std::allocator&lt;unsigned int&gt; &gt;::insert(std::_Vector_const_iterator&lt;unsigned int,std::allocator&lt;unsigned int&gt; &gt; _Where=..., const unsigned int &amp; _Val=0) Line 878 C++ AssimpLoadFileTest.exe!std::vector&lt;unsigned int,std::allocator&lt;unsigned int&gt; &gt;::push_back(const unsigned int &amp; _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&lt;char,std::allocator&lt;char&gt; &gt; &amp; 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&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; strModelName="floor.obj", Assimp::IOSystem * io=0x0110f464) Line 81 C++ AssimpLoadFileTest.exe!Assimp::ObjFileImporter::InternReadFile(const std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; 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&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; 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&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; pFile="floor.obj", unsigned int pFlags=32779) Line 629 C++ AssimpLoadFileTest.exe!DoTheImportThing(const std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; 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() </code></pre> <p>Output:</p> <pre><code>'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). </code></pre> <p>floor.obj:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload