[Solved][1.9] Issue with Basic tutorial : createPlane crash

Problems building or running the engine, queries about how to use features etc.
Post Reply
Tropicao
Gnoblar
Posts: 3
Joined: Mon May 16, 2016 5:18 pm

[Solved][1.9] Issue with Basic tutorial : createPlane crash

Post by Tropicao »

Hello,
I'm a beginner with OGRE 3D and I am currently playing around to learn the API/see if it fits my needs. So far, I have managed to export a custom blender model and load it in Ogre. I did set an autotool environment from zero since I did not manage to make the example application work (compilations/executions issues, with libogre1.9 from repo or with custom libogre build)
I am currently facing an issue with the basic tutorial 2 : if a add the plane in the scene, the program show an exception at render :
OgreApp: /build/ogre-1.9-mqY1wq/ogre-1.9-1.9.0+dfsg1/OgreMain/include/OgreSharedPtr.h:253: T* Ogre::SharedPtr<T>::operator->() const [with T = Ogre::Material]: Assertion `pRep' failed.
[1] 15909 abort (core dumped) ./OgreApp
The code I use is pretty similar to the one presented in the site tutorial. Here it is (disclaimer : the code is clearly not properly organized for an application, I am using these files as sandboxes) :

Base.cpp

Code: Select all

#include "Base.h"
#include "OgreEntity.h"
#include "OgreRenderWindow.h"
#include <OIS/OIS.h>
#include <OgreFrameListener.h>
#include <OgreMeshManager.h>
#include <cmath>
#include <OgrePlane.h>
using namespace std;

Base::Base(void):m_root(NULL), m_window(NULL), m_scene(NULL), m_entity(NULL),m_mainNode(NULL), m_rs(NULL), m_light(NULL), m_camera(NULL), m_vp(NULL)
{
    m_root = new Ogre::Root("plugins.cfg", "ogre.cfg", "Ogre.log");

    if(m_root->restoreConfig() == false)
    {
      if(m_root->showConfigDialog())
      {
          m_window = m_root->initialise(true);
      }
      else
      {
          cout<<"Error : cannot set render settings"<<endl;
          return;
      }
    }
    else
    {
      m_window = m_root->initialise(true);
    }
    m_scene = m_root->createSceneManager(Ogre::ST_GENERIC);

    Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../data", "FileSystem");
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    //Floor
    Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
    Ogre::MeshManager::getSingleton().createPlane(
      "ground",
      Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
      plane,
      500, 500, 10,10,
      true,
      1, 5, 5,
      Ogre::Vector3::UNIT_Z);
    Ogre::Entity* groundEntity = m_scene->createEntity("ground");
    groundEntity->setCastShadows(false);
    m_scene->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);

    m_entity = m_scene->createEntity("MyEntity", "Cube.mesh");
    cout<<"Ogre mesh loaded"<<endl;
    m_mainNode = m_scene->getRootSceneNode()->createChildSceneNode();
    m_entity->setCastShadows(true);
    m_mainNode->attachObject(m_entity);

    m_camera = m_scene->createCamera("Main camera");
    if(m_camera == NULL)
    {
        cout << "Error creating camera"<<endl;
        return;
    }
    m_camera->setPosition(Ogre::Vector3(3, 8, 8));
    m_camera->lookAt(Ogre::Vector3(0, 0, 0));
    m_camera->setNearClipDistance(5);
    m_vp = m_window->addViewport(m_camera);

    m_scene->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.8));
    m_light = m_scene->createLight("MainLight");
    m_light->setPosition(20, 80, 50);
    m_vp->setBackgroundColour(Ogre::ColourValue(0.1, 0.2, 0.1));

    m_root->startRendering();
}
main.cpp

Code: Select all

#include <iostream>
#include "Base.h"

using namespace std;

int main()
{
    Base* base = new Base();
    return 0;
}
plugins.cfg

Code: Select all

PluginFolder=/usr/lib/x86_64-linux-gnu/OGRE-1.9.0
Plugin=RenderSystem_GL
Additionnals informations : I build the app on Ubuntu 16.04 and run it selecting OpenGl in the config dialog box

If I let all the code except the line attaching the "ground" plane to the scene, the app runs perfectly. I also tried to add another mesh in the scene (loading the same mesh in another entity and attaching it to a new node) and it worked.
Maybe I am missing some initialisation with the MeshManager, but the only init function I have seen in the API reference seems to be internal and, as a consequence, not be called from the user code...

Is there anyone knowing anything about this issue ?
Last edited by Tropicao on Thu May 19, 2016 8:26 pm, edited 1 time in total.
Tropicao
Gnoblar
Posts: 3
Joined: Mon May 16, 2016 5:18 pm

Re: [1.9] Issue with Basic tutorial 2 : createPlane crash

Post by Tropicao »

Well... Trying to investigate more specifically on the error, I just saw that it includes a mention about Ogre::Material... I did not set any material, since I thought it was possible to display meshes without texture (Blender habbit I guess). Setting a basic material script and loading it with groundEntity->setMaterialName("grass.material") solved the issue.

I guess I will have to learn to read before going further in Ogre :oops:
Sorry for the dumb post !
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: [Solved][1.9] Issue with Basic tutorial : createPlane cr

Post by Kojack »

If grass.material is the name of a file, then that's not what setmaterialName wants. It wants the name of a material inside of that file, you don't specify the file name (all material files found by the resource system are loaded).
Although you could also create an actual material called grass.material if you wanted, I'm just guessing because it looks more like a file name.

Generally meshes that are missing materials will end up with BaseWhite, one of the built in materials (there's BaseWhite and BaseWhiteNoLighting). I guess because a plane is generated inside of Ogre instead of being loaded through the normal mesh serialiser, it missed a check for empty material name. Sounds like a bug rather than intended behaviour.
Tropicao
Gnoblar
Posts: 3
Joined: Mon May 16, 2016 5:18 pm

Re: [Solved][1.9] Issue with Basic tutorial : createPlane cr

Post by Tropicao »

Indeed Kojack, I made a mistake in my previous post, I did not use "grass.material" in setMaterialName method, but "ground/grass", which is the name I defined inside of "grass.material" script.

An indeed, it would be nice if the default behaviour with a custom mesh was to assign to it a default material :)
Post Reply