Assorted Geekery

Ogre “createRenderWindow” Segmentation fault

So, I thought I would have a play around with the Ogre3d library, not with any particular goals in mind, but it looked very accomplished technically, and a simple clean layout of the API made me think, that it would be nice and quick to knock up something visually satisfying without messing around with low level pure C. Ogre Supports both DirectX and openGL, the later being preferred, as I am running Ubuntu 10.10 with the proprietary NVIDIA driver, which gives me excellent OpenGL support. I pulled down the source, and dev packages and googled for a few tutorials to get started. Unfortunately after copying some of the tutorial code and hitting compile I ran into a segfault, assuming I had made a schoolboy error with my pointers I ran back over the code, but couldn’t spot where I had gone wrong, but I couldn’t see the obvious mistake. What followed was a few hours of quite painful bug squashing which didn’t seem to be documented anywhere else on the internet, I figured I better type up my adventure to save some other poor soul the same wasted evening. [cpp] #include #include using namespace Ogre; using namespace std; int main(int argc, char **argv) { Root* root = NULL; root = new Root(“”,””); root->loadPlugin(“RenderSystem_GL”); root->loadPlugin(“Plugin_OctreeSceneManager”); root->loadPlugin(“Plugin_ParticleFX”); root->loadPlugin(“Plugin_CgProgramManager”); RenderSystem *rSys = NULL; rSys = root->getRenderSystemByName(“OpenGL Rendering Subsystem”); root->setRenderSystem(rSys); root->initialise(false); SceneManager* sceneMgr = NULL; sceneMgr = root->createSceneManager(ST_GENERIC, “MySceneManager”); RenderWindow *window = NULL; window = root->createRenderWindow( “Manual Ogre Window”, 640, 480, false); Camera *camera = NULL; camera = sceneMgr->createCamera(“MainCam”); camera->setAspectRatio(1.33333f); camera->setNearClipDistance(5.0f); camera->setFarClipDistance(1000.0f); camera->setFOVy(Radian(30.0f)); camera->setPosition(200, 10, 200); Viewport *vpTop, *vpBottom; vpBottom = window->addViewport(camera, 0); // create a smaller viewport on top, in the center, 25% of main vp size vpTop = window->addViewport(camera, 1,0.375f, 0.375f,0.25, 0.25); //set bg of vp to blue vpTop->setBackgroundColour(ColourValue(0.0f, 0.0f, 1.0f)); bool KeepOnRendering = true; while (KeepOnRendering) { root->renderOneFrame(); } delete root; return 0; } [/cpp] that should work oh noes seg fault [text] Compiling: main.cpp Linking executable: ./MyOgreApp Output size is 14.38 KB Process terminated with status 0 (0 minutes, 7 seconds) 0 errors, 0 warnings rich@chrome:~/Projects/MyOgreApp$ ./MyOgreApp *** glibc detected *** ./MyOgreApp: free(): invalid pointer: 0x00007effc5c59fe8 *** ======= Backtrace: ========= /lib/libc.so.6(+0x775b6)[0x7effc51b35b6] /lib/libc.so.6(cfree+0x73)[0x7effc51b9e83] [/text] 2nd attempt [cpp] #include #include using namespace Ogre; using namespace std; int main(int argc, char **argv) { LogManager* logMgr = new LogManager; Log *log = LogManager::getSingleton().createLog(“mylog.log”, true, true, false); Root* root = NULL; root = new Root(“”,””); if (root == NULL) { log->logMessage(“(root == NULL)”); } root->loadPlugin(“RenderSystem_GL”); // root->loadPlugin(“Plugin_OctreeSceneManager”); // root->loadPlugin(“Plugin_ParticleFX”); // root->loadPlugin(“Plugin_CgProgramManager”); RenderSystem *rSys = NULL; rSys = root->getRenderSystemByName(“OpenGL Rendering Subsystem”); if (rSys ==NULL) { log->logMessage(“rSys ==NULL”); } else { log->logMessage(“rSys =fine”); } root->setRenderSystem(rSys); root->initialise(false); SceneManager* sceneMgr = NULL; sceneMgr = root->createSceneManager(ST_GENERIC, “MySceneManager”); if (sceneMgr ==NULL) { log->logMessage(“sceneMgr ==NULL”); } else { log->logMessage(“sceneMgr = fine “); } RenderWindow *window = NULL; log->logMessage(“debug 004”); window = root->createRenderWindow( “Manual Ogre Window”, 640, 480, false); log->logMessage(“debug 005”); if (window ==NULL) { log->logMessage(“window ==NULL”); } else { log->logMessage(“window = fine “); } /* Camera *camera = NULL; camera = sceneMgr->createCamera(“MainCam”); if (camera ==NULL) { log->logMessage(“camera ==NULL”); } else { log->logMessage(“camera = fine “); } camera->setAspectRatio(1.33333f); camera->setNearClipDistance(5.0f); camera->setFarClipDistance(1000.0f); camera->setFOVy(Radian(30.0f)); camera->setPosition(200, 10, 200); Viewport *vpTop, *vpBottom; vpBottom = window->addViewport(camera, 0); // create a smaller viewport on top, in the center, 25% of main vp size vpTop = window->addViewport(camera, 1,0.375f, 0.375f,0.25, 0.25); //set bg of vp to blue vpTop->setBackgroundColour(ColourValue(0.0f, 0.0f, 1.0f)); bool KeepOnRendering = true; while (KeepOnRendering) { root->renderOneFrame(); } */ delete root; delete logMgr; return 0; } [/cpp] ok all that checking should work .. but no .. but the debugging statements are enough to roll with [text] sceneMgr = fine debug 004 GLXWindow::create used FBConfigID = 117 GL_VERSION = 3.2.0 NVIDIA 195.36.24 GL_VENDOR = NVIDIA Corporation GL_RENDERER = GeForce 9500 GT/PCI/SSE2 GL_EXTENSIONS = GL_ARB_color_buffer_float GL_ARB_compatibility GL_ARB_copy_buffer GL_ARB_depth_buffer_float GLX_ARB_get_proc_address —snip— *** glibc detected *** ./MyOgreApp: free(): invalid pointer: 0x00007effc5c59fe8 *** ======= Backtrace: ========= /lib/libc.so.6(+0x775b6)[0x7effc51b35b6] /lib/libc.so.6(cfree+0x73)[0x7effc51b9e83] /usr/lib/libstdc++.so.6(_ZNSsD1Ev+0x39)[0x7effc5a02129] /usr/lib/OGRE/RenderSystem_GL.so(+0x5c626)[0x7effbfbf8626] /usr/lib/OGRE/RenderSystem_GL.so(+0x2d147)[0x7effbfbc9147] /usr/lib/OGRE/RenderSystem_GL.so(+0x328c3)[0x7effbfbce8c3] /usr/local/lib/libOgreMain.so.1.7.1(_ZN4Ogre4Root18createRenderWindowERKSsjjbPKSt3mapISsSsSt4lessISsENS_12STLAllocatorISt4pairIS1_SsENS_22CategorisedAllocPolicyILNS_14MemoryCategoryE0EEEEEE+0x31)[0x7effc64047c1] ./MyOgreApp[0x40158c] /lib/libc.so.6(__libc_start_main+0xfd)[0x7effc515ac4d] ./MyOgreApp[0x401129] ======= Memory map: ======== 00400000-00403000 r-xp 00000000 08:01 18096997 /home/rich/Projects/MyOgreApp/MyOgreApp 00602000-00603000 r–p 00002000 08:01 18096997 /home/rich/Projects/MyOgreApp/MyOgreApp [/text] i’m not exactly great at debugging, i have only really used it a few times, but the backtrace seems to imply the stray pointer originated in the plugin library RenderSystem_GL.so [text] rich@chrome:~/Projects/MyOgreApp$ ldd MyOgreApp linux-vdso.so.1 => (0x00007fff11763000) libOgreMain.so.1.7.1 => /usr/local/lib/libOgreMain.so.1.7.1 (0x00007f3827131000) rich@chrome:~/Projects/ogre5/og5_prebake$ ldd /usr/lib/OGRE/RenderSystem_GL.so linux-vdso.so.1 => (0x00007ffffdfff000) libOgreMain-1.6.4.so => /usr/lib/libOgreMain-1.6.4.so (0x00007fc08ba01000) rich@chrome:~/Projects/ogre5/og5_prebake$ ldd /usr/local/lib/OGRE/RenderSystem_GL.so linux-vdso.so.1 => (0x00007fffa27ff000) libOgreMain.so.1.7.1 => /usr/local/lib/libOgreMain.so.1.7.1 (0x00007fd0474c2000) [/text]