[Solved] Ogre 2.0 Crash On Initialisation

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
old_man_auz
Greenskin
Posts: 100
Joined: Tue Jun 15, 2004 5:10 am
Location: Australia

[Solved] Ogre 2.0 Crash On Initialisation

Post by old_man_auz »

Hi,
I have a problem which I describe below. I think that it is a Ogre 2.0 related issue so I hopefully this is in the correct spot.

Firstly, a disclaimer: I'm a rubbish programmer. I'm self taught and there is large gaps in my knowledge. I can usually work out my problems just by mucking around for days/weeks but this one has me beat - hopefully I'm not doing something stupid.

Back Ground Info
I have a framework that I have been using to create Ogre projects with for 4-5 years now. I occasionally modifiy it when I learn a new way of doing things. I decided I would convert my rendering system over to Ogre 2.0 and want to rewrite my object system from a component - object orientated design to a component - data orientated design. So I started a new project and stripped out everything everything except the Rendering system and the input system to make sure that I could get Ogre 2.0 to work and then rebuild the new game object system on top of that.

My Code
I used this code: https://gist.github.com/tahsmith/41d7f2e7d43be5ea1572 as a basis for my Ogre 2.0 initialisation. The key difference is that instead of

Code: Select all

Ogre::Root root("", "", "OgreLog.txt");
I do:

Code: Select all

m_pOgreRoot = new Ogre::Root("", "", "Ogre.log");
and I store the render window, scene manager and camera as member variables in my Render System class.

This is the code that I'm using:
Main.cpp

Code: Select all

Engine engine;
if( engine.Initialise() == true )
{
    engine.ExecuteGameLoop();
}
Engine.cpp (Initialise function)

Code: Select all

// These classes are singletons that I use so I can log messages anywhere and save/load settings anywhere in my code. I have been using them for a few years so I don't think the problem is in these classes.
[Logger class is initialised here]
[Settings class is initialised here]

// Initialise Render Manager
if( !m_bShutdownAndExit )
{
    m_pRenderManager = new RenderManager();
    if( !m_pRenderManager->Initialise() )
    {
        g_Logger->LogError( "ERROR: Failed to initialise the Render Manager." );
        m_bShutdownAndExit = true;
    }
}

// Initialise Input Manager
if( !m_bShutdownAndExit )
{
    m_pInputManager = new InputManager();
    if( !m_pInputManager->Initialise( m_pRenderManager->getOgreRenderWindow() ) )
    {
        g_Logger->LogError( "ERROR: Failed to initialise Input Manager." );
        m_bShutdownAndExit = true;
    }
}
For completeness, here is my Render Manager Initialise function (I have removed all my Logging code to simplify the example here)
RenderManager.cpp (Initialise Function)

Code: Select all

// Create root Ogre object
m_pOgreRoot = new Ogre::Root("", "", "Ogre.log");

// Load Plugins
Ogre::Root::getSingleton().loadPlugin( "./plugins/RenderSystem_Direct3D11");
Ogre::Root::getSingleton().loadPlugin( "./plugins/Plugin_ParticleFX");
Ogre::Root::getSingleton().loadPlugin( "./plugins/Plugin_CgProgramManager");

// Use the first available render system
Ogre::RenderSystem* renderSys = m_pOgreRoot->getAvailableRenderers()[0];
m_pOgreRoot->setRenderSystem(renderSys);

// Set video mode
renderSys->setConfigOption("Full Screen", "No");
renderSys->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour");

// Make the window
m_pRenderWindow = m_pOgreRoot->initialise(true);

// Start compositor
m_pOgreRoot->initialiseCompositor();	

// Initialise resources for real-time shader
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../media/RTShaderLib", "FileSystem", "Essential");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../media/RTShaderLib/materials", "FileSystem", "Essential");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../media/RTShaderLib/hlsl", "FileSystem", "Essential");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../media/RTShaderLib/cg", "FileSystem", "Essential");
Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Essential");

// Initialise real-time shader
bool ok = Ogre::RTShader::ShaderGenerator::initialize();
auto &shaderGenerator = Ogre::RTShader::ShaderGenerator::getSingleton();
	
// Necessary for D3D11. It has no fixed function pipeline.
ShaderGeneratorTechniqueResolverListener sgtrl(&shaderGenerator);
Ogre::MaterialManager::getSingleton().addListener(&sgtrl);

// Initialise the scene manager
Ogre::SceneManager* m_pSceneManager = m_pOgreRoot->createSceneManager(Ogre::ST_GENERIC, 1, Ogre::INSTANCING_CULLING_SINGLETHREAD);
shaderGenerator.addSceneManager(m_pSceneManager);

// Load resource locations
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../media/models", "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../media/programs", "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../media/programs/cg", "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../media/programs/hlsl", "FileSystem", "General");
Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General");

// Initialise camera & workspace
m_pCamera = m_pSceneManager->createCamera("Camera");

// Set up workspace
Ogre::CompositorManager2* pCompositorManager = m_pOgreRoot->getCompositorManager2();
const Ogre::String workspaceName = "scene workspace";
pCompositorManager->createBasicWorkspaceDef(workspaceName, Ogre::ColourValue::Black);
pCompositorManager->addWorkspace(m_pSceneManager, m_pRenderWindow, m_pCamera, workspaceName, true);

return true;
I don't call "m_pOgreRoot->startRendering();" as I manually call 'RenderOneFrame()' in my game loop.

The Problem
Now, the problem. The render manager initialises fine and the code gets back to Engine.cpp Initialisation function and then hits the:

Code: Select all

// Initialise Input Manager
if( !m_bShutdownAndExit )
part of my code and crashes on that line. 'm_bShutdownAndExit' is declared as type 'bool' in my Engine.h file. As far as I can work out, the 'm_bShutdownAndExit' bool memory is corrupted and I have no Idea why. If I comment out the render system initialisation the code runs to the Input Manager initialisation fine and crashes because it doesnt get a valid RenderWindow pointer - which is to be expected. I found a page on the wiki about memory corruption but I couldn't find anything on it that seemed relevant to what I was doing.

My Ogre log file if it is helpful: http://pastebin.com/6Rh3EsyU
The only thing of interest I can find in there is the "Compiler error: unknown error in RTShaderSystem.material(23): token "rtshader_system" is not recognized" line. I can make this go away by moving the RealTime Shader Generator initialisation code before the initialising of the real time shader resources, but I get the same memory corruption. I changed it back to match the code I originally copied from as I thought the author knew what he was doing more than I did.

I'm using the Ogre 2.0 code which I downloaded on the '30th of September, 2014'

I have compiled the sample browser and the Direct X 11 rendersystem and the sample browser does run correctly, though not all samples work.

I also wondered if my issue was covered in the Ogre 2.0 porting manual but I couldn't find it as dark_sylinc's website is down and it is hosted there? (BTW dark_sylinc, if you read this, is your website coming back?)

Thanks for any help and let me know if more info is needed.

Luke
Last edited by old_man_auz on Thu Oct 23, 2014 8:49 am, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Converted Project to Ogre 2.0 - Crash On Initialisation

Post by dark_sylinc »

Hi!

My website is up. A few users have reported they have issues accessing my site from different ISPs. I had to move to another hosting service a few months ago and it appears to be some ISPs block the IP address coming from these new servers from time to time.
I know for sure I won't be renewing contract with this hosting provider when it ends. You can access my site from a web proxy until the matter is resolved.
The porting manual can also be found here or in the repo's doc folder.

As for the issue at matter: It is failing in your code, so I can't help you much with it.
BUT:
Start single stepping and see when m_bShutdownAndExit is still readable. Then place a data breakpoint on it's address (use &m_bShutdownAndExit in the watch window to get the address) and see if it gets hit.
Another possible problem is that this gets corrupted. Try adding another breakpoint on the address of this. It's also possible that ecx got overwriten and the pointer to this is now garbage. If that happened, something went seriously wrong with the compiler, linking the libraries, or random data was executed as code. This is worst case scenario and would require you to look at the assembly from the debugger to track why ecx gets overwritten and never restored correctly.

First start by not initialising the RTSS and using DX9. The RTSS wasn't tested thoroughly and might be causing the memory corruption you're suspecting.
Another point of failure is that Ogre 2.0 CTP requires you to call Root::initialiseCompositor after the first window has been created (this was fixed in the experimental branches).

Last but not least, check your compiler flags. Your project's should match OgreMain's. Due to a quite important oversight, NDEBUG and DEBUG are very important. If you compile your exe with NDEBUG and OgreMain w/out NDEBUG (or viceversa, or using DEBUG instead of NDEBUG, or mixing them), all hell breaks loose. It's in my TODO list.

Pasting the callstack could help diagnosing the problem, and the values of local variables.
old_man_auz
Greenskin
Posts: 100
Joined: Tue Jun 15, 2004 5:10 am
Location: Australia

Re: Converted Project to Ogre 2.0 - Crash On Initialisation

Post by old_man_auz »

Ha,
I added NDEBUG to the preprocessor definitions and program is now working. I'm getting a crash somewhere else, but I think its my code - I'm tracking it down now.

Thanks for your help.

I got to your site via a web proxy too.

Luke
User avatar
Zonder
Ogre Magi
Posts: 1168
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 73

Re: Converted Project to Ogre 2.0 - Crash On Initialisation

Post by Zonder »

dark_sylinc wrote:Hi!

My website is up. A few users have reported they have issues accessing my site from different ISPs. I had to move to another hosting service a few months ago and it appears to be some ISPs block the IP address coming from these new servers from time to time.
I know for sure I won't be renewing contract with this hosting provider when it ends. You can access my site from a web proxy until the matter is resolved.
Out of interest which hosting provider? These things are handy to know.
There are 10 types of people in the world: Those who understand binary, and those who don't...
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: [Solved] Ogre 2.0 Crash On Initialisation

Post by dark_sylinc »

Zonder wrote:Out of interest which hosting provider? These things are handy to know.
"NUTHOST".
It's a local provider. I chose it because they seemed profesional and also offered reasonable payment methods (which is something difficult given my country of origin)
User avatar
Olganix
Halfling
Posts: 41
Joined: Thu Nov 06, 2008 4:18 pm

Re: [Solved] Ogre 2.0 Crash On Initialisation

Post by Olganix »

Hi.

I did'nt understand why my application work in debug, but crash in release with some strange thing like:
-bad ptr when i go throw the OgreMain.dll
-strange code execution moves after a breakpoint.
It's look like a multithread problem, but my application thread are not started before the crash.

With your post I found why : "NDEBUG" is missing in release on OgreMain and plugins projects (after put them in my application's solution (visual studio 2008) ), I don't know why.

Thank a lot. you save my day ;) (but not my yesterday :lol: )
Post Reply