Advertisement

OGRE_NEW Root("",""); Access violation reading location 0x00500065

Started by October 24, 2024 04:50 PM
3 comments, last by Sekt4nt 1 month, 3 weeks ago

//Compiled with OGRE 1.6.5 Visual C++ 2019

#include "OgreApplication.h"

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

cOgreApplication::cOgreApplication()
{
m_Root = NULL;
m_Window = NULL;
m_WindowHandle = NULL;
m_SceneManager = NULL;
m_Camera = NULL;
m_Viewport = NULL;
m_SceneListener = NULL;
}

//---------------------------------------------
//Configures OGRE SDK
bool cOgreApplication::init(bool showStartDialog)
{
//Create OGRE root object
m_Root = OGRE_NEW Root("","");

// Load resource paths from config file
ConfigFile cf;
cf.load("resources.cfg");

// Go through all sections & settings in the file
ConfigFile::SectionIterator seci = cf.getSectionIterator();

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

ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}


m_Root->loadPlugin("RenderSystem_Direct3D9");
m_Root->loadPlugin("RenderSystem_GL");

//Check. Should show dialog for user conifgure of graphics? Or automatic?
if(showStartDialog)
{
//User configure
if(m_Root->showConfigDialog())
m_Window = m_Root->initialise(true, "My Sample Application");
}
else
{
//Automatic; set default render system. First, DirectX. Then OpenGL.

RenderSystem *rs = m_Root->getRenderSystemByName("Direct3D9 Rendering Subsystem");

if(rs)
{
m_Root->setRenderSystem(rs);
}
else
{
//Use OpenGL if possible

rs = m_Root->getRenderSystemByName("OpenGL Rendering Subsystem");

if(rs)
m_Root->setRenderSystem(rs);
}

if(rs)
{
rs->setConfigOption("Full Screen", "No");
rs->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour");

m_Window = m_Root->initialise(true, "My Sample Application");
}
}

if(m_Window)
{
//Create Scene Manager
m_SceneManager = m_Root->createSceneManager(ST_GENERIC, "Default SceneManager");

//Create Scene Camera
m_Camera = m_SceneManager->createCamera("Camera");
m_Camera->setPosition(Vector3(0,0,500));
m_Camera->lookAt(Vector3(0,0,-300));
m_Camera->setNearClipDistance(5);

//Create Viewport Object
// Create one viewport, entire window
m_Viewport = m_Window->addViewport(m_Camera);
m_Viewport->setBackgroundColour(ColourValue(0,0,0));

// Alter the camera aspect ratio to match the viewport
m_Camera->setAspectRatio(
Real(m_Viewport->getActualWidth()) / Real(m_Viewport->getActualHeight()));

TextureManager::getSingleton().setDefaultNumMipmaps(5);

ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

//Create Scene Listener to receive event notifications
m_SceneListener = new cSceneManager();
m_SceneListener->m_Window = m_Window;

m_Root->addFrameListener(m_SceneListener);

//Set Log Manager Detail level to low
LogManager::getSingleton().setLogDetail(LL_LOW);

createScene();

//Start render loop
m_Root->startRendering();

return true;
}

return false;
}

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

void cOgreApplication::createScene()
{
m_SceneManager->setAmbientLight(ColourValue(0, 0, 0));
//Light* l = m_SceneManager->createLight("MainLight");
//l->setPosition(20,80,50);

Light* light = m_SceneManager->createLight("Light1");
light->setType(Light::LT_POINT);
light->setPosition(Vector3(0, 150, 700));
light->setDiffuseColour(1.0, 0.0, 0.0);
light->setSpecularColour(1.0, 0.0, 0.0);

Entity *ent1 = m_SceneManager->createEntity( "Robot", "MyMesh.mesh" );
SceneNode *node1 = m_SceneManager->getRootSceneNode()->createChildSceneNode( "RobotNode" );
//ent1->setMaterialName("BaseWhiteNoLighting");

node1->attachObject(ent1);

node1->translate(Vector3(0,0,450));
node1->setScale(4,4,4);
}

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

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

cSceneManager::cSceneManager()
{
m_Window = NULL;
}

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

bool cSceneManager::frameRenderingQueued(const FrameEvent& evt)
{
if(m_Window->isClosed()) return false;

return true;
}


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


Compiles successfully in release mode, when trying to run it starts, writes a log and stops working. If you open it through VS 2019, it will show that the error is on this line

m_Root = OGRE_NEW Root("","");

Here are my includes:

OgreMain.lib;User32.lib

Here is the folder with the exe file:

Media:
MyMesh.material
MyMesh.mesh
.log
OgreMain.dll

OgreProject.exe

RenderSystem_Direct3D9.dll

RenderSystem_GL.dll

None

In your debugger look at your call stack. Look at the function that's having the issue. That will help you track where the actual issue is.

The docs for the constructor says it is expecting different parameters. As a hunch the first parameter is supposed to be either nullptr or the address of a properly completed Ogre::AbiCookie structure, and you're instead passing the address of an empty string. You've probably got a compiler warning about incompatible pointer types.

Advertisement

@frob Thank you for your reply !

As I mentioned in code, I use 1.6.5 version of OGRE, so right version of the constructor is -
Root (const String &pluginFileName="plugins"OGRE_BUILD_SUFFIX".cfg", const String &configFileName="ogre.cfg", const String &logFileName="Ogre.log")
documentation

But I will try tomorrow look at the call stack. Thank you so much !

None

@frob I looked in a call stack, there is nothing I can see because excpetion occured in dll file msvcr80.dll

None

This topic is closed to new replies.

Advertisement