Segfault when calling loadPlugin from a scripting language

Problems building or running the engine, queries about how to use features etc.

Segfault when calling loadPlugin from a scripting language

Postby aerique » Wed Dec 10, 2008 9:02 am

Hi all,

This could very well be a Lisp question but I chose to ask it here first. I've also Googled and searched this forum for answers and did find some threads but none solved my problem.

I'm trying to create a language binding for Ogre from Common Lisp (ECL specifically at the moment) and Ogre segfaults after calling loadPlugin. This also happened with Swig bindings I created on SBCL (CL implementation). It does not happen when I call loadPlugin from a small test C++ program.

Also, when I use a plugins.cfg everything loads fine so there's a workaround but I still want to know why this happens since I'll probably run into it again at a later point.

At the moment I'm not at the machine I'm developing the bindings on so I can't get you gdb or strace output unfortunately. I did use them though (although I'm not very familiar with them.. though I probably will be in the near future :) ). Ogre.log shows the same (can't get at it atm either) except it complains it can't find a plugins.cfg.

Fun fact: it did infact load the plugin once succesfully when running ECL from strace ("strace ecl") but I wasn't able to reproduce it. ("strace -e trace=open ecl" always gave the same error like below)

I'm basically hoping someone else who'se made language bindings has run into this same problem and knows the solution.

Note: The pastes below use Ogre 1.6.0 which I decided to try yesterday but I had the same problem with 1.4.9. There's also some commented out code and random Ogre::String stuff since I was trying out different things.

Here's the C++ program and its output:

Code: Select all
// ogre-test.cpp
//
// Compile with: g++ `pkg-config --cflags --libs OGRE` ogre-test.cpp

#include "Ogre.h"

int main (int argc, char *argv[])
{
    //Ogre::Root* ogre = new Ogre::Root( "", "" );
    Ogre::Root* ogre = new Ogre::Root();

    ogre->loadPlugin(Ogre::String("RenderSystem_GL"));

    return 0;
}


Code: Select all
$ ./a.out
Creating resource group General
Creating resource group Internal
Creating resource group Autodetect
SceneManagerFactory for type 'DefaultSceneManager' registered.
Registering ResourceManager for type Material
Registering ResourceManager for type Mesh
Registering ResourceManager for type Skeleton
MovableObjectFactory for type 'ParticleSystem' registered.
OverlayElementFactory for type Panel registered.
OverlayElementFactory for type BorderPanel registered.
OverlayElementFactory for type TextArea registered.
Registering ResourceManager for type Font
ArchiveFactory for archive type FileSystem registered.
ArchiveFactory for archive type Zip registered.
FreeImage version: 3.10.0
This program uses FreeImage, a free, open source image library supporting all common bitmap
formats. See http://freeimage.sourceforge.net for details
Supported formats: bmp,ico,jpg,jif,jpeg,jpe,jng,koa,iff,lbm,mng,pbm,pbm,pcd,pcx,pgm,
pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,
xbm,xpm,gif,hdr,g3,sgi,exr,j2k,j2c,jp2
DDS codec registering
Registering ResourceManager for type HighLevelGpuProgram
Registering ResourceManager for type Compositor
MovableObjectFactory for type 'Entity' registered.
MovableObjectFactory for type 'Light' registered.
MovableObjectFactory for type 'BillboardSet' registered.
MovableObjectFactory for type 'ManualObject' registered.
MovableObjectFactory for type 'BillboardChain' registered.
MovableObjectFactory for type 'RibbonTrail' registered.
plugins.cfg not found, automatic plugin loading disabled.
*-*-* OGRE Initialising
*-*-* Version 1.6.0 (Shoggoth)
Loading library RenderSystem_GL
Installing plugin: GL RenderSystem
OpenGL Rendering Subsystem created.
Plugin successfully installed


Here's the ECL binding and its output:

Code: Select all
(defun ffi-ogre-root ()
  (if *ogre*
      *ogre*
      (setf *ogre* (ffi:c-inline () () :pointer-void "new Ogre::Root()"
                                 :one-liner t))))


(defun ffi-ogre-root-load-plugin (plugin)
  (ffi:c-inline (*ogre* plugin) (:pointer :cstring) :void "{
      Ogre::Root* ogre = (Ogre::Root*) #0;
      //ogre->loadPlugin(Ogre::String(plugin));
      ogre->loadPlugin(\"RenderSystem_GL\");
     }"))


Code: Select all
ECL (Embeddable Common-Lisp) 0.9l (CVS 2008-06-19 17:09)
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.  Top level.
CL-USER[1]> (load "init")
;;; Loading #P"/usr/local/pub/ekwis/software/okra-0.1/init.lisp"
; loading system definition from ogre-test.asd into #<ASDF0 package>
;;; Loading "/usr/local/pub/ekwis/software/okra-0.1/ogre-test.asd"
; registering #<ASDF:SYSTEM :OGRE-TEST 163091992> as OGRE-TEST
;;; Loading "/usr/local/pub/ekwis/software/okra-0.1/specials.fas"
;;; Loading "/usr/local/pub/ekwis/software/okra-0.1/ffi.fas"
;;; Loading "/usr/local/pub/ekwis/software/okra-0.1/ogre-test.fas"
#P"/usr/local/pub/ekwis/software/okra-0.1/init.lisp"
CL-USER[2]> (ffi-ogre-root)
Creating resource group General
Creating resource group Internal
Creating resource group Autodetect
SceneManagerFactory for type 'DefaultSceneManager' registered.
Registering ResourceManager for type Material
Registering ResourceManager for type Mesh
Registering ResourceManager for type Skeleton
MovableObjectFactory for type 'ParticleSystem' registered.
OverlayElementFactory for type Panel registered.
OverlayElementFactory for type BorderPanel registered.
OverlayElementFactory for type TextArea registered.
Registering ResourceManager for type Font
ArchiveFactory for archive type FileSystem registered.
ArchiveFactory for archive type Zip registered.
FreeImage version: 3.10.0
This program uses FreeImage, a free, open source image library supporting all common bitmap
formats. See http://freeimage.sourceforge.net for details
Supported formats: bmp,ico,jpg,jif,jpeg,jpe,jng,koa,iff,lbm,mng,pbm,pbm,pcd,pcx,pgm,
pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,
xbm,xpm,gif,hdr,g3,sgi,exr,j2k,j2c,jp2
DDS codec registering
Registering ResourceManager for type HighLevelGpuProgram
Registering ResourceManager for type Compositor
MovableObjectFactory for type 'Entity' registered.
MovableObjectFactory for type 'Light' registered.
MovableObjectFactory for type 'BillboardSet' registered.
MovableObjectFactory for type 'ManualObject' registered.
MovableObjectFactory for type 'BillboardChain' registered.
MovableObjectFactory for type 'RibbonTrail' registered.
plugins.cfg not found, automatic plugin loading disabled.
*-*-* OGRE Initialising
*-*-* Version 1.6.0 (Shoggoth)
#<foreign :VOID 09c52008>
CL-USER[3]> (ffi-ogre-root-load-plugin "RenderSystem_GL")
Loading library RenderSystem_GL
Segmentation violation.
Broken at SI:BYTECODES.No restarts available.
Broken at SI:BYTECODES.
** BREAK [LEVEL 2] >


The ECL error message isn't very useful. They need to work on that ;-)
User avatar
aerique
Halfling
 
Posts: 59
Kudos: 0
Joined: 18 Oct 2007
Location: The Netherlands

Postby jacmoe » Wed Dec 10, 2008 10:41 am

What happens when you run a bare bones Ogre test program not using plugins.cfg?
Without ECL, I mean.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, Fueled by Passion.
Ogre AppWizards - Ogre project wizards for VC 8-10, Code::Blocks and KDevelop.
OgreAssimpConverter - command-line to convert models to Ogre format.
TwOgreGUI - wrapper for AntTweakBar GUI library.
I accept donations | Me on Google+
User avatar
jacmoe
OGRE Moderator
OGRE Moderator
 
Posts: 21024
Kudos: 161
Joined: 22 Jan 2004
Location: Denmark

Postby aerique » Wed Dec 10, 2008 10:55 am

jacmoe wrote:What happens when you run a bare bones Ogre test program not using plugins.cfg?


That's what the first two code fragments show :) It works in that case.
User avatar
aerique
Halfling
 
Posts: 59
Kudos: 0
Joined: 18 Oct 2007
Location: The Netherlands

Postby aerique » Fri Dec 12, 2008 1:19 pm

Right, I had some time to spend on this and twice now (once running ecl under strace and once running it under Insight (gdb GUI)) it loaded RenderSystem_GL succesfully. This is while running under Linux 2.6.26-1-686 #1 SMP and everything being compiled with g++ (Debian 4.3.2-1) 4.3.2.

All other times it segfaulted though, but since it doesn't seem to be due to Ogre::String or std::string I might just go ahead with using a plugins.cfg instead of loadPlugin and hope I don't run into it again.

Anyway here's some gdb output.

Stacktrace:

Code: Select all
...
#0 Ogre::Root::loadPlugin () at new_allocator.h:108


/usr/include/c++/4.3.2/ext/new_allocator.h:

Code: Select all
     46   /**
     47    *  @brief  An allocator that uses global new, as per [20.4].
     48    *
     49    *  This is precisely the allocator defined in the C++ Standard.
     50    *    - all allocation calls operator new
     51    *    - all deallocation calls operator delete
     52    */
     53   template<typename _Tp>
     54     class new_allocator
     55     {
...
    104       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    105       // 402. wrong new expression in [some_] allocator::construct
    106       void
    107       construct(pointer __p, const _Tp& __val)
    108       { ::new((void *)__p) _Tp(__val); }


I'm useless with gdb. This contructor is called a lot of times and it only segfaults in the loadPlugin case.
User avatar
aerique
Halfling
 
Posts: 59
Kudos: 0
Joined: 18 Oct 2007
Location: The Netherlands

Re: Segfault when calling loadPlugin from a scripting language

Postby ronybeck » Mon Jan 26, 2009 11:09 pm

Did you manage to solve this? I get a segfault and the backtrace shows me segfaulting at the same line 108 in new_allocator.h

Code: Select all
 
      construct(pointer __p, const _Tp& __val)
      [b]{ ::new((void *)__p) _Tp(__val); [/b]}    <------------ segfault here


Interestingly enough, it happens when I push_back() a pointer from a billboard set to a vector. Completely different operation, same result.
ronybeck
Kobold
 
Posts: 30
Kudos: 0
Joined: 13 Aug 2008

Re: Segfault when calling loadPlugin from a scripting language

Postby aerique » Wed May 06, 2009 9:13 am

ronybeck wrote:Did you manage to solve this? I get a segfault and the backtrace shows me segfaulting at the same line 108 in new_allocator.h


No, did you? :)

I went back to making intermediary C wrappers and calling those from Lisp.

Was you problem when directly coding in C++?
User avatar
aerique
Halfling
 
Posts: 59
Kudos: 0
Joined: 18 Oct 2007
Location: The Netherlands


Return to Help

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 6 guests