Null pointer from getParentSceneNode

Null pointer from getParentSceneNode

Postby paul424 » 03 Feb 2019, 12:28

Hi, I am writing here , because the question is not solid enough for github issues.

What I wanted to do, was to add the rotation of the canon trap, but something went very wrong.

I do in TrapCannon::shoot():

{l Code}: {l Select All Code}
    Tile* tt = getCoveredTile(0);
    BuildingObject* obj ;
    if(tt != nullptr)
        obj = getBuildingObjectFromTile(tt);

   
    if(obj != nullptr)
        obj->getParentSceneNode();



this for sure should get me the SceneNode of the cannon mesh, but I get nullptr instead.
The whole BuildingObject inherits from RenderedMovableEntity, which has the code of
prepering proper mesh in RenderManager ( it does renderedMovableEntity->setParentSceneNode(node->getParentSceneNode()); also)

Where is the fault of my thinking ?

{l Code}: {l Select All Code}
void RenderManager::rrCreateRenderedMovableEntity(RenderedMovableEntity* renderedMovableEntity)
{
    std::string meshName = renderedMovableEntity->getMeshName();
    std::string tempString = renderedMovableEntity->getOgreNamePrefix() + renderedMovableEntity->getName();

    Ogre::SceneNode* node = mRoomSceneNode->createChildSceneNode(tempString + "_node");

    node->setPosition(renderedMovableEntity->getPosition());
    node->roll(Ogre::Degree(renderedMovableEntity->getRotationAngle()));
    Ogre::Entity* ent = nullptr;
    if(!meshName.empty())
    {
        ent = mSceneManager->createEntity(tempString, meshName + ".mesh");
        node->attachObject(ent);
    }

    renderedMovableEntity->setParentSceneNode(node->getParentSceneNode());
    renderedMovableEntity->setEntityNode(node);

    // If it is required, we hide the tile
    if((renderedMovableEntity->getHideCoveredTile()) &&
       (renderedMovableEntity->getOpacity() >= 1.0))
    {
        Tile* posTile = renderedMovableEntity->getPositionTile();
        if(posTile == nullptr)
            return;

        std::string tileName = posTile->getOgreNamePrefix() + posTile->getName();
        if (!mSceneManager->hasEntity(tileName))
            return;

        Ogre::Entity* entity = mSceneManager->getEntity(tileName);
        entity->setVisible(false);
    }

    if ((ent != nullptr) && (renderedMovableEntity->getOpacity() < 1.0f))
        setEntityOpacity(ent, renderedMovableEntity->getOpacity());
}
User avatar
paul424
OD Moderator
 
Posts: 644
Joined: 24 Jan 2012, 13:54

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest