Segfault when trying to create multiple scene nodes.

Problems building or running the engine, queries about how to use features etc.
Post Reply
doesntmatterwho
Gnoblar
Posts: 4
Joined: Fri Jan 09, 2015 11:53 am

Segfault when trying to create multiple scene nodes.

Post by doesntmatterwho »

I'm following the tutorials on the ogre wiki. I have an example, where I want to spawn more meshes but somehow it gives me failed assertion. The code is :

Code: Select all


#include "TutorialApplication.h"
#include "functions.h"
#include <stdlib.h>
//-------------------------------------------------------------------------------------
TutorialApplication::TutorialApplication(void)
{
}
//-------------------------------------------------------------------------------------
TutorialApplication::~TutorialApplication(void)
{
}

//-------------------------------------------------------------------------------------
void TutorialApplication::createScene(void)
{
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
    mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
 
    Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh");
    entNinja->setCastShadows(true);
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);
 
    Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
 
    Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
	

        //THIS IS WHERE I WANT TO SPAWN MULTIPLE MESHES
	Ogre::Entity* entGround = 0;
	for (int i = 0 ; i <10; i++ ) { 
		entGround = mSceneMgr->createEntity(toString(i), "ground");
		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround);
	}
    
 
    entGround->setMaterialName("Examples/Rockwall");
    entGround->setCastShadows(false);
 
    Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
    pointLight->setType(Ogre::Light::LT_POINT);
    pointLight->setPosition(Ogre::Vector3(0, 150, 250));
 
    pointLight->setDiffuseColour(1.0, 0.0, 0.0);
    pointLight->setSpecularColour(1.0, 0.0, 0.0);
 
    Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight");
    directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
    directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0));
    directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0));
 
    directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 )); 
 
    Ogre::Light* spotLight = mSceneMgr->createLight("spotLight");
    spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
    spotLight->setDiffuseColour(0, 0, 1.0);
    spotLight->setSpecularColour(0, 0, 1.0);
 
    spotLight->setDirection(-1, -1, 0);
    spotLight->setPosition(Ogre::Vector3(300, 300, 0));
 
    spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));
}

The error message is this:

Image


Can anybody tell me what am I doing wrong or how can I spawn multiple meshes the correct way?
User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4304
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 135
Contact:

Re: Segfault when trying to create multiple scene nodes.

Post by spacegaier »

In which lines does the crash occur? I assume in the for-loop?
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...
doesntmatterwho
Gnoblar
Posts: 4
Joined: Fri Jan 09, 2015 11:53 am

Re: Segfault when trying to create multiple scene nodes.

Post by doesntmatterwho »

For sure the loop is causing the error, because when not using loop everything works fine. I'm not sure where the error itself comes from - from the loop or from later rendering code. The exact line causing the error is this:

Code: Select all

entGround = mSceneMgr->createEntity(toString(i), "ground");
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Segfault when trying to create multiple scene nodes.

Post by c6burns »

Step through the program in the debugger. You might learn the situation is different than assumed.
doesntmatterwho
Gnoblar
Posts: 4
Joined: Fri Jan 09, 2015 11:53 am

Re: Segfault when trying to create multiple scene nodes.

Post by doesntmatterwho »

The code is so simple that there is no need for the debuger.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Segfault when trying to create multiple scene nodes.

Post by Mind Calamity »

This is a bug in OGRE with prefabs, they all crash on render, I'm not sure what's up with that, I'll make a report.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Segfault when trying to create multiple scene nodes.

Post by Mind Calamity »

Okay, I just found out why it crashes, the MaterialPtr in the entity is null, and so it crashes, to fix this, move these 2 lines inside the loop:

Code: Select all

    entGround->setMaterialName("Examples/Rockwall");
    entGround->setCastShadows(false);
It should be assigned a default material, but it's not for some reason.

Reported the issue here: https://ogre3d.atlassian.net/browse/OGRE-467
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Segfault when trying to create multiple scene nodes.

Post by c6burns »

doesntmatterwho wrote:The code is so simple that there is no need for the debuger.
Ignorance is bliss
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Segfault when trying to create multiple scene nodes.

Post by Mind Calamity »

Personally, I've learned the hard way that there's no code issue where a debugger would not be helpful/needed, except maybe memory corruptions, those suckers are hard to track, and a debugger sure as hell doesn't help.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Segfault when trying to create multiple scene nodes.

Post by c6burns »

I agree there is nothing too simple for at least a sanity check in the debugger. It should be every programmer's kneejerk reaction, especially when the app segvs. Yes, in this case it's an issue in Ogre (though why you would want 10 planes with no material, I don't know ... nevertheless crashing is bad and Ogre should at least assert somewhere instead of crash).

Re: corruption, gdb has a feature where you can break on read or write to a given address. I assume visual studio has the same feature, just I haven't had to use it there yet. That can reaaaaaaaally help with memory issues :)
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Segfault when trying to create multiple scene nodes.

Post by Kojack »

c6burns wrote:Re: corruption, gdb has a feature where you can break on read or write to a given address. I assume visual studio has the same feature, just I haven't had to use it there yet. That can reaaaaaaaally help with memory issues :)
Yep, in VS it's called a data breakpoint. You can monitor a block of any size of bytes at any address for changes. I don't know of breaking on read though.
doesntmatterwho
Gnoblar
Posts: 4
Joined: Fri Jan 09, 2015 11:53 am

Re: Segfault when trying to create multiple scene nodes.

Post by doesntmatterwho »

Thank you.
Post Reply