I was trying to code a function to create a copy of a mesh with inverted normals orientation of faces that would be used if the mesh is used somewhere with a negative scale.
I got stuck very early, because it segfaults when cloning the mesh, accessing faulty address 0x20, so it's probably accessing a member variable of a nullptr struct/class. The mesh isn't a nullptr (checked), it's loaded (checked) and it can be replicated easily in a minimal case scenario.
What is enough to cause the segfault:
In Tutorial02 (Variable Framerate), I add this after the line when the item Cube_d.mesh is created:
Code: Select all
Ogre::Mesh* meshOrig = static_cast<Ogre::Mesh*>(Ogre::MeshManager::getSingleton().getResourceByName("Cube_d.mesh").getPointer());
Ogre::Mesh* cloned = meshOrig->clone("Cube_d2.mesh").getPointer();
Code: Select all
Thread 1 "Sample_Tutorial" received signal SIGSEGV, Segmentation fault.
0x00007ffff70ccda4 in memcpy (
__len=<error reading variable: Cannot access memory at address 0x20>,
__src=0x7fffd80dc000, __dest=0x7fffd84dc540)
at /usr/include/x86_64-linux-gnu/bits/string3.h:53
53 return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
#0 0x00007ffff70ccda4 in memcpy (
__len=<error reading variable: Cannot access memory at address 0x20>,
__src=0x7fffd80dc000, __dest=0x7fffd84dc540)
at /usr/include/x86_64-linux-gnu/bits/string3.h:53
#1 Ogre::VertexArrayObject::clone (this=0x7fffdbe188c8,
vaoManager=0x7fffe017f358,
sharedBuffers=sharedBuffers@entry=0x7fffffffd980)
at blablabla/ogre-2.1/OgreMain/src/Vao/OgreVertexArrayObject.cpp:224
#2 0x00007ffff6e12fbd in Ogre::SubMesh::clone (this=<optimised out>,
parentMesh=0x7fffe01f9340)
at blablabla/ogre-2.1/OgreMain/src/OgreSubMesh2.cpp:340
#3 0x00007ffff6e2668c in Ogre::Mesh::clone (this=this@entry=0x7fffe01f31b0,
newName="Cube_d2.mesh", newGroup="")
at blablabla/ogre-2.1/OgreMain/src/OgreMesh2.cpp:218
#4 0x000000000040a9c9 in Demo::MyGameState::createScene01 (
this=0x7fffffffdb40)
at blablabla/ogre-2.1/Samples/2.0/Tutorials/Tutorial02_VariableFramerate/MyGameState.cpp:37
#5 0x000000000040b110 in mainApp ()
at blablabla/ogre-2.1/Samples/2.0/Tutorials/Tutorial02_VariableFramerate/Tutorial02_VariableFramerate.cpp:49
#6 0x000000000040a37b in main ()
Just for completeness, this is the whole code I am trying to get working is here (I could not check anything after the clone, so it's kinda useless).