Crash with OgreRenderer

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

S0ul_Killer
Just popping in
Just popping in
Posts: 4
Joined: Sun Feb 19, 2012 23:36

Crash with OgreRenderer

Postby S0ul_Killer » Sun Feb 19, 2012 23:53

Hello,
I currently have runtime errors using the CEGUI Ogre Renderer.
First the specs:
I am working on Windows 8 Dev. Preview (also compiling the code under Ubuntu 11.10)
I am using Visual Studio 10
I am using Ogre 1.7.3 (custom build)
I am using CeGui 0.7.6 (also tried 0.7.5 both custom build against ogre 1.7.3)
Now the error:
When I am trying to load a scheme file the system crashes. The error is:
Run-Time Check Failure #2 - Stack around the variable 'input' was corrupted

The Debugger tracks the crash down to
OgreResourceProvider::loadRawDataContainer(const String& filename, RawDataContainer& output, const String& resourceGroup)

Which lies in the CEGUIOgreResourceProvider.cpp file.
The code of this method is:

Code: Select all

    String orpGroup;
    if (resourceGroup.empty())
        orpGroup = d_defaultResourceGroup.empty() ?
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str() :
            d_defaultResourceGroup;
    else
        orpGroup = resourceGroup;

    Ogre::DataStreamPtr input = Ogre::ResourceGroupManager::getSingleton().
        openResource(filename.c_str(), orpGroup.c_str());

    if (input.isNull())
        CEGUI_THROW(InvalidRequestException(
            "OgreCEGUIResourceProvider::loadRawDataContainer: Unable to open "
            "resource file '" + filename + "' in resource group '" + orpGroup +
            "'."));

    Ogre::String buf = input->getAsString();
    const size_t memBuffSize = buf.length();

    unsigned char* mem = new unsigned char[memBuffSize];
    memcpy(mem, buf.c_str(), memBuffSize);

    output.setData(mem);
    output.setSize(memBuffSize);

In the debugger it looks like the variable orpGroup has a wierd value:
+orpGroup {d_cplength=7 d_reserve=32 d_encodedbuff=0x0fd30a90 "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ •|b/ø Ó" ...} CEGUI::String

Also the Ogre Resource System is initialised as I can create textured Ogre Objects.

The code looks like this:

Code: Select all

//process: create the cegui renderer
mCeguiRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
CEGUI::SchemeManager::getSingleton().create((CEGUI::utf8*)"VanillaSkin.scheme");

If i comment the last line the code runs just fine. (Except that i am not able to use CeGui then).
I did of course internet research. Therefore I checked the resource.cfg file from Ogre. I have tried both version i found:

Code: Select all

[Imagesets]
FileSystem=../../media/cegui/imagesets
[Fonts]
FileSystem=../../media/cegui/fonts
[Schemes]
FileSystem=../../media/cegui/schemes
[LookNFeel]
FileSystem=../../media/cegui/looknfeel
[Layouts]
FileSystem=../../media/cegui/layouts

As well as:

Code: Select all

[CEGUI]
FileSystem=../../media/cegui/imagesets
FileSystem=../../media/cegui/fonts
FileSystem=../../media/cegui/schemes
FileSystem=../../media/cegui/looknfeel
FileSystem=../../media/cegui/layouts
FileSystem=../../media/cegui/lua_scripts
FileSystem=../../media/cegui/xml_schemas

Also I tried different scheme files. Plus I checked that all dll files are present in the binary folder.

The log files didn't show an error at all, as Ogres last message is OIS is successfully created (according to the Ogre tutorials) and Cegui log tells me that the Cegui System was successfully created.

Any help would be appreciated!
Thanks in advance!/

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Crash with OgreRenderer

Postby Kulik » Mon Feb 20, 2012 08:45

Very likely a memory corruption somewhere prior to that code. Does it always crash at the same point? On GNU/Linux I would check with valgrind, dunno about Windows tools.

Make sure everything is compiled with the same flags, same runtime libs, same everything - some sort of a mismatch there is a common caveat on Windows.

S0ul_Killer
Just popping in
Just popping in
Posts: 4
Joined: Sun Feb 19, 2012 23:36

Re: Crash with OgreRenderer

Postby S0ul_Killer » Mon Feb 20, 2012 11:19

Thanks for the quick reply.
I forgot about the linux output, sorry.
If I run the program it gives me a "segmentation fault".
The callgrind output here tracks the crash to the XmlParser:
Process terminating with default action of signal 11 (SIGSEGV)
Access not within mapped region at address 0x3F8000B8
at 0x57AD0A0: CEGUI::XMLParser::initialise() (in /usr/lib/libCEGUIBase.so.1.2.0)
by 0x7186463: CEGUI::System::System(CEGUI::Renderer&, CEGUI::ResourceProvider*, CEGUI::XMLParser*, CEGUI::ImageCodec*, CEGUI::ScriptModule*, CEGUI::String const&, CEGUI::String const&) (CEGUISystem.cpp:246)
by 0x7186F5C: CEGUI::System::create(CEGUI::Renderer&, CEGUI::ResourceProvider*, CEGUI::XMLParser*, CEGUI::ImageCodec*, CEGUI::ScriptModule*, CEGUI::String const&, CEGUI::String const&) (CEGUISystem.cpp:1900)
by 0x5B19F62: CEGUI::OgreRenderer::bootstrapSystem() (CEGUIOgreRenderer.cpp:132)
...

I have recompiled CEGUI multiple times and always made sure that i use the same dependencies as my project.

I also tried to work with the Visual Studio Profiler, but that didn|t work out well (it just sazs "unspecified error").

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Crash with OgreRenderer

Postby CrazyEddie » Mon Feb 20, 2012 11:38

I agree with Kulik - this is definitely memory corruption. You can tell because the first error you posted says so :)

Please post your code. There is no use posting our code, as in the first post - we already know what it says; we wrote it ;) Please also post a callstack / backtrace (though that's likely to be either corrupt or otherwise unhelpful).

CE.

S0ul_Killer
Just popping in
Just popping in
Posts: 4
Joined: Sun Feb 19, 2012 23:36

Re: Crash with OgreRenderer

Postby S0ul_Killer » Mon Feb 20, 2012 11:55

Okay,
the code is pretty much the same as in the Ogre Tutorial 7.
Here is the header file:

Code: Select all

/**
\brief Main Game Content Mangement
*/
class GameManager : public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener, public Base::Singleton<GameManager> {
//note: make the system relevant data accessable from the outside
public:
    //! Holds the ogre root element
    Ogre::Root *mRoot;
    //! Holds the main ogre camera that will be used
    Ogre::Camera* mCamera;
    //! Holds the scene manager that will be used
    Ogre::SceneManager* mSceneMgr;
    //! Holds the render window that is used
    Ogre::RenderWindow* mWindow;
    //! Holds the file to the resource configuration
    Ogre::String mResourcesCfg;
    //! Holds the file to the plugin configuration
    Ogre::String mPluginsCfg;
    //! Holds the main input manager of OIS
    OIS::InputManager* mInputManager;
    //! Holds a pointer to the currently used mouse device
    OIS::Mouse*    mMouse;
    //! Holds a pointer to the currently used keyboard device
    OIS::Keyboard* mKeyboard;
    //! Holds the Cegui Rendering module
    CEGUI::OgreRenderer* mCeguiRenderer;

private:
    //! Used to display the cursor in menus
    bool mCursorWasVisible;
    //! Defines if the game should be closed now
    bool mShutDown;

public:
    /**
    \brief Default Constructor
    */
    GameManager(void);
   
    /**
    \brief Default Destructor
    */
    ~GameManager(void);
   
    /**
    \brief Starts the application
    */
    void go();

    /**
    \brief Sets the shutdown flag
    */
    void shutdown();

    static GameManager& getSingleton();

    static GameManager* getSingletonPtr();

private:
    /**
    \brief General setup method that calls all subfunctions
    */
    bool setup();

    /**
    \brief Calls the Ogre Config Dialog and creates the renderwindow
    */
    bool configure();

    /**
    \brief Load resource pathes
    */
    void setupResources();

    /**
    \brief Init and add a resource listener
    */
    void createResourceListener();

    /**
    \brief Load all reosurces
    */
    void loadResources();

    /**
    \brief Setup the main camera
    */
    void createCamera();
    /**
    \brief Creates the input system and adds this class as FrameListener
    */
    void createFrameListener();
    /**
    \brief Setup a viewport and adjusts the camera to it
    */
    void createViewports();
    /**
    \brief Chooses the type of scenemanager that will be used
    */
    void chooseSceneManager();

    /**
    \brief Initializes CEGUI
    */
    void createCeGui();
   
    /**
    \brief Used to adjust mouse clipping area
    */
    void windowResized(Ogre::RenderWindow* rw);

    /**
    \brief Unattach OIS before window shutdown (very important under Linux)
    */
    void windowClosed(Ogre::RenderWindow* rw);

   // Ogre::FrameListener
    bool frameRenderingQueued(const Ogre::FrameEvent& evt);
   
    //OIS::KeyListener
    bool keyPressed( const OIS::KeyEvent &arg );
    bool keyReleased( const OIS::KeyEvent &arg );
    //OIS::MouseListener
    bool mouseMoved( const OIS::MouseEvent &arg );
    bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
    bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ); 
};


And here is the cpp code:

Code: Select all

#include "GameManager.h"

template<> GameManager* Base::Singleton<GameManager>::pSingleton = 0;
GameManager* GameManager::getSingletonPtr(void)
{
    return pSingleton;
}
GameManager& GameManager::getSingleton() {
    assert( pSingleton ); 
    return ( *pSingleton );
}

//process: intialise almost everything as a null-pointer
GameManager::GameManager() : mRoot(0),
    mCamera(0),
    mSceneMgr(0),
    mWindow(0),
    mResourcesCfg(Ogre::StringUtil::BLANK),
    mPluginsCfg(Ogre::StringUtil::BLANK),
    mCursorWasVisible(false),
    mShutDown(false),
    mInputManager(0),
    mMouse(0),
    mKeyboard(0),
    mCeguiRenderer(0)
{

}

GameManager::~GameManager() {
    //process: close the window and delete the ogre root
    Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);
    windowClosed(mWindow);
    delete mRoot;
}

//---------

bool GameManager::setup(void) {
    //process: create the log manager
    LogManager::createSingleton("stwa_log", true, TxtLog, Normal, true, true);
    //process: create the ogre root using the plugin file
    mRoot = new Ogre::Root(mPluginsCfg);
    //process: load all the resources
    setupResources();
    //process: show the config dialog and close game if it is exited
    if (!configure()) return false;

    chooseSceneManager();
    createCamera();
    createViewports();

    //process: just set some options for textures
    Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);

    //process: create a resource listener
    createResourceListener();
    //process: load all resources (media files)
    loadResources();
    //process: create this as frame listener
    createFrameListener();

    //process: init cegui
    createCeGui();

    return true;
}

void GameManager::setupResources(void) {
    //process: load the resource file
    Ogre::ConfigFile cf;
    cf.load(mResourcesCfg);

    //process: iterate through the resource file and add the resource locations
    Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

    Ogre::String secName, typeName, archName;
    while (seci.hasMoreElements())
    {
        secName = seci.peekNextKey();
        Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
        Ogre::ConfigFile::SettingsMultiMap::iterator i;
        for (i = settings->begin(); i != settings->end(); ++i)
        {
            typeName = i->first;
            archName = i->second;
            Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
                archName, typeName, secName);
        }
    }
}

bool GameManager::configure() {
    //process: show the ogre config dialog
    if(mRoot->showConfigDialog()) {
        //process: create the render window
        mWindow = mRoot->initialise(true, WINDOW_TITLE);
        return true;
    }
    else {
        return false;
    }
}

void GameManager::chooseSceneManager(void) {
    //process: choose the type of the scene manager
    mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
}

void GameManager::createCamera(void) {
    //process: create the basic camera
    mCamera = mSceneMgr->createCamera("GameCam");

    //process: set the camera at a default starting position
    mCamera->setPosition(Ogre::Vector3(0,0,80));
    //process: set the orientation and the clipping pos of the cam
    mCamera->lookAt(Ogre::Vector3(0,0,-300));
    mCamera->setNearClipDistance(5);
}

void GameManager::createViewports(void) {
    //process: create the main viewport and set the background color to black
    Ogre::Viewport* vp = mWindow->addViewport(mCamera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));

    //process: set the aspect ratio of the camera so that it fits the viewport size
    mCamera->setAspectRatio(
        Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
}

void GameManager::createResourceListener(void) {
    //TODO: implement this later on
}

void GameManager::loadResources(void) {
    //process: load all resources that were earlier added to this resource manager
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}

void GameManager::createFrameListener(void) {
    Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
    OIS::ParamList pl;
    size_t windowHnd = 0;
    std::ostringstream windowHndStr;

    mWindow->getCustomAttribute("WINDOW", &windowHnd);
    windowHndStr << windowHnd;
    pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
    //process: create the OIS InputManager based on the created parameter list
    mInputManager = OIS::InputManager::createInputSystem( pl );
    //process: create input listeners for keyboard and mouse events (later on also joystick = gamepad)
    mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
    mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
    //process: add this class to catch the key events
    mMouse->setEventCallback(this);
    mKeyboard->setEventCallback(this);

    //process: call the resize method to match the data to the window size
    windowResized(mWindow);

    //process: add this class to catch the resize and close events
    Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
    //process: add this as a framelistener for ogre
    mRoot->addFrameListener(this);
}

void GameManager::createCeGui() {
    //process: create the cegui renderer
    mCeguiRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
    //process: set some properties
    /*CEGUI::Imageset::setDefaultResourceGroup("Imagesets");
    CEGUI::Font::setDefaultResourceGroup("Fonts");
    CEGUI::Scheme::setDefaultResourceGroup("Schemes");
    CEGUI::WidgetLookManager::setDefaultResourceGroup("LookNFeel");
    CEGUI::WindowManager::setDefaultResourceGroup("Layouts");*/

    // setup default group for validation schemas
    /*CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
    if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
        parser->setProperty("SchemaDefaultResourceGroup", "schemas");*/

    CEGUI::SchemeManager::getSingleton().create((CEGUI::utf8*)"VanillaSkin.scheme");

    //mSceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1));
    //mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
}

//--------

void GameManager::go(void) {
    //process: set the name of the resource (media) and plugin files
#ifdef _DEBUG
    mResourcesCfg = "resources_d.cfg";
    mPluginsCfg = "plugins_d.cfg";
#else
    mResourcesCfg = "resources.cfg";
    mPluginsCfg = "plugins.cfg";
#endif

    //process: try to setup the game
    if (!setup())
        return;
    //process: start the rendering process
    mRoot->startRendering();
}

//----------------

bool GameManager::frameRenderingQueued(const Ogre::FrameEvent& evt) {
    //safty: check if the window is closed
    if(mWindow->isClosed())
        return false;
    //safty: check if the system is set to shutdown
    if(mShutDown)
        return false;

    //process: capture the input
    mKeyboard->capture();
    mMouse->capture();

    return true;
}

void GameManager::shutdown() {
    mShutDown = true;
}

//--------------

bool GameManager::keyPressed( const OIS::KeyEvent &arg ) {
    //process: allow to take screenshots
    if (arg.key == OIS::KC_SYSRQ)
    {
        mWindow->writeContentsToTimestampedFile("screenshot", ".jpg");
    }
    //process: all other options are only allowed in debug mode
#ifdef _DEBUG
    //process: cycle rendering modes
    else if (arg.key == OIS::KC_R)
    {
        Ogre::String newVal;
        Ogre::PolygonMode pm;

        switch (mCamera->getPolygonMode())
        {
        case Ogre::PM_SOLID:
            newVal = "Wireframe";
            pm = Ogre::PM_WIREFRAME;
            break;
        case Ogre::PM_WIREFRAME:
            newVal = "Points";
            pm = Ogre::PM_POINTS;
            break;
        default:
            newVal = "Solid";
            pm = Ogre::PM_SOLID;
        }
    }
    //process: refresh all textures
    else if(arg.key == OIS::KC_F5)
    {
        Ogre::TextureManager::getSingleton().reloadAll();
    }
    //process: always exit the game with esc
    else if (arg.key == OIS::KC_ESCAPE)
    {
        mShutDown = true;
    }
#endif

    return true;
}

bool GameManager::keyReleased( const OIS::KeyEvent &arg ) {
    return true;
}

bool GameManager::mouseMoved( const OIS::MouseEvent &arg ) {
    return true;
}

bool GameManager::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) {
    return true;
}

bool GameManager::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) {
    return true;
}

//---------

void GameManager::windowResized(Ogre::RenderWindow* rw) {
    unsigned int width, height, depth;
    int left, top;
    rw->getMetrics(width, height, depth, left, top);

    const OIS::MouseState &ms = mMouse->getMouseState();
    ms.width = width;
    ms.height = height;
}

void GameManager::windowClosed(Ogre::RenderWindow* rw) {
    //Only close for window that created OIS (the main window in these demos)
    if( rw == mWindow )
    {
        if( mInputManager )
        {
            mInputManager->destroyInputObject( mMouse );
            mInputManager->destroyInputObject( mKeyboard );

            OIS::InputManager::destroyInputSystem(mInputManager);
            mInputManager = 0;
        }
    }
}

//------------------------------------------------------

//the main loop

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        //process: create the application
        GameManager app;

        //process: try to run it
        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }

        return 0;
    }

#ifdef __cplusplus
}
#endif

S0ul_Killer
Just popping in
Just popping in
Posts: 4
Joined: Sun Feb 19, 2012 23:36

Re: Crash with OgreRenderer

Postby S0ul_Killer » Mon Feb 20, 2012 16:41

I just tried to compile MyGUI against my Ogre build (under Windows).
Compiling works just fine, but when I start a sample I get almost the same error (corrupted arround variable "stream").
Therefore I think it might be something Ogre-internal (or something related to the dependencies). Anyway since I don't have time to check that I'll be using the Ogre build-in Interface (Overlay-Elements).

Thanks for the help!

Sigma
Just popping in
Just popping in
Posts: 2
Joined: Wed Mar 21, 2012 04:16

[SOLVED] Re: Crash with OgreRenderer

Postby Sigma » Wed Mar 21, 2012 04:31

Cross posting from another thread post I made with an identical problem:

http://www.cegui.org.uk/phpBB2/viewtopic.php?f=10&t=5024#p28604

I encountered this error and thought I'd post my fix. Hopefully it will save someone else a bit of pain.

For me, it occurred because I had built CEGUI with stl debug iterators turned off (for debug builds), but I had built Ogre and my Application with them turned on. Thus any call that passes an stl class (such as string) into CEGUI would eventually trigger a stack corruption error.

Either rebuild all your sources with iterator debugging turned off, or rebuild CEGUI with it turned on.

Search for _HAS_ITERATOR_DEBUGGING and _SECURE_SCL in your project settings under C/C++, Preprocessor, Definitions. Also double check if you have it #defined somewhere in your own application.

This worked for me, but if it doesn't work for you then you probably should double check other compiler setting differences between CEGUI and your Application.


Hope that helps!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 19 guests