OGRE Initialization Issue

Problems building or running the engine, queries about how to use features etc.
leviskim18
Gnoblar
Posts: 10
Joined: Sat Aug 03, 2024 6:12 am

OGRE Initialization Issue

Post by leviskim18 »

Ogre Version: ogre-14.2.6
Operating System: Windows 10
Render System: not selected yet.

I have struggling with Ogre Initailization issue.
I have tried with Current Stable Release: v14.2.6 – 2. June 2024 and my custom build with CMake.

When I tried to build with the below sample code. (Mostly I follow the tutorial of https://ogrecave.github.io/ogre/api/latest/setup.html)

Code: Select all

#include <Ogre.h>
#include <OgreApplicationContext.h>
#include <iostream>

int main(int argc, char** argv) {
	OgreBites::ApplicationContext ctx("OgreTutorialApp");
	ctx.initApp();

Ogre::Root* root = ctx.getRoot();
Ogre::RenderWindow* window = ctx.getRenderWindow();

Ogre::SceneManager* sceneMgr = root->createSceneManager();
Ogre::RTShader::ShaderGenerator* shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
shadergen->addSceneManager(sceneMgr);

Ogre::Light* light = sceneMgr->createLight("MainLight");
Ogre::SceneNode* lightNode = sceneMgr->getRootSceneNode()->createChildSceneNode();
lightNode->setPosition(0, 10, 15);
lightNode->attachObject(light);

Ogre::SceneNode* camNode = sceneMgr->getRootSceneNode()->createChildSceneNode();
camNode->setPosition(0, 0, 15);
camNode->lookAt(Ogre::Vector3(0, 0, -1), Ogre::Node::TS_PARENT);

Ogre::Camera* cam = sceneMgr->createCamera("myCam");
cam->setNearClipDistance(5);
cam->setAutoAspectRatio(true);
camNode->attachObject(cam);

window->addViewport(cam);

Ogre::Entity* ent = sceneMgr->createEntity("Sinbad.mesh");
Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode();
node->attachObject(ent);

try {
	root->startRendering();
}
catch (const Ogre::Exception& e) {
	std::cerr << "An exception has occurred: " << e.getFullDescription().c_str() << std::endl;
}

ctx.closeApp();
return 0;
}

When I run ths code, Unhanlded exception occurs at this line.
OgreBites::ApplicationContext ctx("OgreTutorialApp");

Exception thrown at 0x00007FFC0FC8B699 in OgreTest.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000D4800FEEC0.
Unhandled exception at 0x00007FFC0FC8B699 in OgreTest.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000D4800FEEC0.

It seems to be related to Ogre::String Encoding issue.

In OgreApplicationContextBase.cpp, when it is initialized, the appName is delivered as

  • appName "0\x1d¥\xe\x1" const std::string &
  • mAppName is emptry.

Code: Select all

ApplicationContextBase::ApplicationContextBase(const Ogre::String& appName)
{
    mAppName = appName;
    mFSLayer = new Ogre::FileSystemLayer(mAppName);

if (char* val = getenv("OGRE_CONFIG_DIR"))
{
    Ogre::String configDir = Ogre::StringUtil::standardisePath(val);
    mFSLayer->setConfigPaths({ configDir });
}

mRoot = NULL;
mOverlaySystem = NULL;
mFirstRun = true;

#ifdef OGRE_BUILD_COMPONENT_RTSHADERSYSTEM
    mMaterialMgrListener = NULL;
    mShaderGenerator = NULL;
#endif
}

Are there any points I should be aware of, or settings needed when building the library or configuring the project related to this issue?

Image

Image

rpgplayerrobin
Gnoll
Posts: 680
Joined: Wed Mar 18, 2009 3:03 am
x 379

Re: OGRE Initialization Issue

Post by rpgplayerrobin »

It seems to not even be able to get the string correctly into the first function?
I would suggest you to build Ogre from Source, that way you know that your compiler actually works with your own user code.

If you use libs and dlls that has been compiled with another compiler than your own, you might get issues like this.

Also, first try a Clean and then a Rebuild of your entire project, because that can sometimes also cause these issues.

paroj
OGRE Team Member
OGRE Team Member
Posts: 2107
Joined: Sun Mar 30, 2014 2:51 pm
x 1132

Re: OGRE Initialization Issue

Post by paroj »

verify that you either build release or relwithdebug (debug does not work with the prebuild SDK) and that you are using VS2019 or later

leviskim18
Gnoblar
Posts: 10
Joined: Sat Aug 03, 2024 6:12 am

Re: OGRE Initialization Issue

Post by leviskim18 »

Hi @paroj

Thanks for your help. I confirmed that the SDK built as release and relwithdebug is not working on the debug mode. And when I tried on the release mode, it is working well.

Nevertheless, I need a debug SDK for smooth debugging. So I have tried to build the SDK by myself with CMake approach, but the debug building of SDK returns some errors. On the other hands, other release buildings are working well. I havn't reconfigured any option in CMake.

I just downloaded the source code from here (https://www.ogre3d.org/download/sdk/sdk-ogre) and just opened it with CMake. I don't have much to share about my process. Did I make any mistake or miss any key settings for Ogre debug building? If you notice any thing, can you let me know?

paroj
OGRE Team Member
OGRE Team Member
Posts: 2107
Joined: Sun Mar 30, 2014 2:51 pm
x 1132

Re: OGRE Initialization Issue

Post by paroj »

rpgplayerrobin
Gnoll
Posts: 680
Joined: Wed Mar 18, 2009 3:03 am
x 379

Re: OGRE Initialization Issue

Post by rpgplayerrobin »

Also see my post about how to build Ogre, it works with all versions I have tried over the years:
viewtopic.php?p=554037#p554037

See there that the debug version does fail for some unimportant projects, but it will still compile valid .lib and .dll for all other projects, which is enough to debug Ogre in your real application.