System.AccessViolationException buidling with OGRE

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

kurisu-san
Just popping in
Just popping in
Posts: 3
Joined: Tue Jan 31, 2012 22:50

System.AccessViolationException buidling with OGRE

Postby kurisu-san » Tue Jan 31, 2012 23:05

Hi,

I am making a game, and it uses OGRE and is successfully compiled with it.

My VS2010 solution contains two projects, Game and Gui, where Game is a console application and Gui is a static linked library, and Game references Gui.

G:\Game\Code\MyGame is the solution directory.

The Gui project has a class called HUD which I create an instance of, i then call a void method called init() to initialise all the CEGUI stuff and then i create an instance of Game and start the game.. etc.

Looks pretty much like this:

Code: Select all


int main()
{

Game game;
HUD hud;

game.init();
hud.init();

game.start();

}




I have built all the CEGUI stuff successfully (its version 0.7.6) and added the lib directory to Gui, and the lib files required:

CEGUIBase_d.lib
CEGUIOgreRenderer_d.lib

I have also made sure to add the bin directory for the dlls for CEGUI to the Game project so it can see them when it runs.


This is the code that is currently in the void init() method in the HUD class.

Code: Select all


void HUD::init()
{

char cCurrentPath[FILENAME_MAX];

if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath) / sizeof(char)))
{
   return;
}

cCurrentPath[sizeof(cCurrentPath) - 1] = '\0';

printf ("The current working directory is %s", cCurrentPath);

CEGUI::OgreRenderer* renderer = &CEGUI::OgreRenderer::bootstrapSystem();

// initialise the required dirs for the DefaultResourceProvider
CEGUI::DefaultResourceProvider* rp = static_cast<CEGUI::DefaultResourceProvider*>
(CEGUI::System::getSingleton().getResourceProvider());
 
rp->setResourceGroupDirectory("schemes",      "../media/cegui/imagesets/");
rp->setResourceGroupDirectory("imagesets",      "../media/cegui/imagesets/");
rp->setResourceGroupDirectory("fonts",         "../media/cegui/fonts/");
rp->setResourceGroupDirectory("layouts",      "../media/cegui/layouts/");
rp->setResourceGroupDirectory("looknfeels",      "../media/cegui/looknfeel/");
rp->setResourceGroupDirectory("lua_scripts",   "../media/cegui/lua_scripts/");
 
//// This is only needed if you are using Xerces and need to
//// specify the schemas location
////rp->setResourceGroupDirectory("schemas", "../../XMLRefSchema/");
////Now that is done, we have a nice set of resource groups defined with their target directories set. Finally, to get the system to use these new directories, we set the default resource groups to be used:
//// set the default resource groups to be used
//
CEGUI::Imageset::setDefaultResourceGroup("imagesets");
CEGUI::Font::setDefaultResourceGroup("fonts");
CEGUI::Scheme::setDefaultResourceGroup("schemes");
CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
CEGUI::WindowManager::setDefaultResourceGroup("layouts");
CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
 
/* Again, you only need to this one if you are using xerces and have
//defined a group for schemas.
//CEGUI::XercesParser::setSchemaDefaultResourceGroup("schemas");
*/


CEGUI::SchemeManager::getSingleton().create( "TaharezLookSkin.scheme" );

CEGUI::System::getSingleton().setDefaultFont( "DejaVuSans-10" );
CEGUI::System::getSingleton().setDefaultMouseCursor( "TaharezLook", "MouseArrow" );

CEGUI::Window* myRoot = CEGUI::WindowManager::getSingleton().createWindow( "DefaultWindow", "_MasterRoot" );

CEGUI::System::getSingleton().setGUISheet( myRoot );

CEGUI::Window *myImageWindow = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage","PrettyWindow" );

CEGUI::System::getSingleton().getGUISheet()->addChildWindow(myImageWindow);

}



I added a little bit of code at the top so I could see the current working directory in the console just incase.

All the cegui datafiles are in "F:\Game\Code\MyGame\media\cegui"

Now when I run the application, it runs fine, ogre all gets initialised correctly until it gets to this line :

Code: Select all

rp->setResourceGroupDirectory("schemes",      "../media/cegui/imagesets/");


Then I get a System.AccessViolationException :

The current working directory is F:\Game\Code\MyGame\Debug
Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at CEGUI.DefaultResourceProvider.setResourceGroupDirectory(DefaultResourcePro
vider* , String* , String* )
at MyGame.Gui.HUD.{ctor}(HUD* ) in f:\game\code\mygame\gui\hud.cpp:line 42
at _mainCRTStartup()


Can anyone shed any light on this?

Any help would be very very appreciated.

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

Re: System.AccessViolationException buidling with OGRE

Postby CrazyEddie » Wed Feb 01, 2012 17:49

It's because the OgreRenderer::bootstrap creates a CEGUI::OgreResourceProvider and not a CEGUI::DefaultResource provider. The main idea is that you'll be using Ogre's resource system to provide the files to CEGUI.

CE.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 9 guests