[Fixed] [Bug] Dropping creature causes Ogre exception

[Fixed] [Bug] Dropping creature causes Ogre exception

Postby DunmerLord » 04 Aug 2013, 14:14

When picking up a creature an then dropping it sometimes I get the following error:
*** ERROR: Internal Ogre3D exception: OGRE EXCEPTION(2:InvalidParametersException): Node 'Knight_006_node' already was a child of 'Creature_scene_node'. in Node::addChild at /home/carlos/.ogre/OgreMain/src/OgreNode.cpp (line 309)

I've found it is caused by the RenderManager::rrAttachTile( const RenderRequest& renderRequest) method, which I think is called when a creature is to be shown on screen.

How to reproduce this bug:
Pick up a creature, drop it, pick it up again and drop it rapidly on the same tile. The game crashes with the error above. I think this only happens if you do it on a tile that is not shown when first loading the level, that is, you have to scroll the screen, but I'm not sure.

By debugging the code I found that when this bug happens the situation is something like this. The scene node of the creature is a child of "Creature_scene_node" but then we try to assign the creature node as a child of "Hand_node". In the documentation of the addChild method ([url link=http://www.ogre3d.org/docs/api/html/classOgre_1_1Node.html#ad3d47c3e2b3fa5deab934b93666c7f3d"]here[/link]) it's said that the node we are trying to attach as a child must be detached from it's current parent before.

Any ideas on how to fix this? I've tried creatureNode->getParentSceneNode()->removeChild(creatureNode), but this causes a segmentation fault :(

Find attached the stack trace from gdb and the error output.
Attachments
already_was_a_child-output.txt
Console output
(675 Bytes) Downloaded 484 times
already_was_a_child-stack.txt
Stack trace
(1.47 KiB) Downloaded 494 times
Last edited by DunmerLord on 12 Aug 2013, 12:02, edited 1 time in total.
DunmerLord
 
Posts: 13
Joined: 19 Jul 2013, 17:48

Re: [Bug] Dropping creature causes Ogre exception

Postby paul424 » 04 Aug 2013, 16:43

Sorry I have had broken computer and now problems with my ISP.
Well, for what I can deduce well it happens when you scroll the screen.
Probably it has something to do that active -- visible Creatures are keept in MortuaryQuad . Actually there are two



{l Code}: {l Select All Code}
   
    cerr << "countnodes " << gameMap->myCullingQuad.countNodes() <<endl; 
    gameMap->myCullingQuad.holdRootSemaphore();
    MortuaryQuad tmpQuad((gameMap->myCullingQuad));

    gameMap->myCullingQuad.releaseRootSemaphore();

    tmpQuad.cut(Segment(ogreVectorsArray[1],ogreVectorsArray[0]));
    tmpQuad.cut(Segment(ogreVectorsArray[0],ogreVectorsArray[3]));
    tmpQuad.cut(Segment(ogreVectorsArray[3],ogreVectorsArray[2]));
    tmpQuad.cut(Segment(ogreVectorsArray[2],ogreVectorsArray[1]));



tmpQuad is computed from myCullingQuad, by cutting it with Segments derived from screen corners .

Either it is problem with semaphores or .... some invariant isn't kept hard to guess from the finger .....
User avatar
paul424
OD Moderator
 
Posts: 660
Joined: 24 Jan 2012, 13:54

Re: [Bug] Dropping creature causes Ogre exception

Postby DunmerLord » 04 Aug 2013, 18:21

I think you are right Paul. I've been doing some more tests and I think the bug happens when you pick up a creature, then scroll the screen so the tile where the creature was is no longer visible and then drop it.

I'll have to learn how this hide/show entities mechanism works.
DunmerLord
 
Posts: 13
Joined: 19 Jul 2013, 17:48

Re: [Bug] Dropping creature causes Ogre exception

Postby paul424 » 06 Aug 2013, 21:34

So how's the progress of dissecting the OD's code , especially CameraManager.cpp part I suppose ?
If anything unclear to you in source code , just ask , I will try to answer the best as I can ...
Best to start working with code is doing cosmetic changes or reorganizing code structure ( but not semantic ) to more readible for visiting programmer ....
User avatar
paul424
OD Moderator
 
Posts: 660
Joined: 24 Jan 2012, 13:54

Re: [Bug] Dropping creature causes Ogre exception

Postby DunmerLord » 07 Aug 2013, 22:33

I think I found a fix for this bug. I changed the code of the rrAttachTile method to this:
{l Code}: {l Select All Code}
void RenderManager::rrAttachTile( const RenderRequest& renderRequest ) {
    GameEntity* curEntity = static_cast<GameEntity*> ( renderRequest.p );
    Ogre::SceneNode* creatureNode = sceneManager->getSceneNode( curEntity->getName() + "_node" );

    Ogre::SceneNode* parentNode = creatureNode->getParentSceneNode();
    if (parentNode == nullptr) {
        curEntity->pSN->addChild(creatureNode);
    } else {
        curEntity->pSN = parentNode;
    }

}

Now it adds a child to the entity's pSN only if the creature's scene node doesn't have a parent already. When the creature scene node does have a parent we assign it to the pSN attribute. That way when you drop the creature the pSN changes from "Hand_node" to "Creature_scene_node".

The game seems to work fine with this change, although I don't know if could be missing something.

I'll carry on studying the code. I agree reorganizing the code is a very good way to get familiar with it. You have to admit that the Creature::doTurn() method does need a bit of refactoring :)
DunmerLord
 
Posts: 13
Joined: 19 Jul 2013, 17:48

Re: [Bug] Dropping creature causes Ogre exception

Postby paul424 » 07 Aug 2013, 22:44

Yeap, ask someone of alien_wolf, andrewbuck40, oln, svenskmand to give you permission to push your code into git repo, sorry if I repeat myself , donno if I told you that to you already. Hmm about doTurn : it has single input and output at least :P . Probably you would read those actions and probablities from some config file . But first I must write some simpler xml config files for what's in Test.level .
User avatar
paul424
OD Moderator
 
Posts: 660
Joined: 24 Jan 2012, 13:54

Re: [Bug] Dropping creature causes Ogre exception

Postby oln » 08 Aug 2013, 08:47

Nice work!
I'll sort git access if you give me your sf.net account name.

DunmerLord {l Wrote}:
I'll carry on studying the code. I agree reorganizing the code is a very good way to get familiar with it. You have to admit that the Creature::doTurn() method does need a bit of refactoring :)


Yes, it certainly does :)
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: [Bug] Dropping creature causes Ogre exception

Postby DunmerLord » 09 Aug 2013, 10:39

Sorry guys, I couldn't see this until now.

Oln, I just sent a message to you with my sourceforge username. Now I'm at work but I'll upload the fix as soon as I can.

Regards
DunmerLord
 
Posts: 13
Joined: 19 Jul 2013, 17:48

Re: [Bug] Dropping creature causes Ogre exception

Postby oln » 09 Aug 2013, 15:40

Ok, gave git access to the username you provided.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: [Bug] Dropping creature causes Ogre exception

Postby DunmerLord » 09 Aug 2013, 18:22

I just committed the fix to the development branch. I use Code::Blocks to work on the code and it automatically deleted the trailing spaces at the end of every line. I hope you don't mind I think it's cleaner that way.

Should I add [fixed] to the subject or do you have to test if I've broken anything?
DunmerLord
 
Posts: 13
Joined: 19 Jul 2013, 17:48

Re: [Bug] Dropping creature causes Ogre exception

Postby paul424 » 09 Aug 2013, 18:58

Well OD does not have any unit tests ....

At least you could have check whether it builds properly , cause it contained my method' name blunder in FppMode.cpp , I just fixed it :)
User avatar
paul424
OD Moderator
 
Posts: 660
Joined: 24 Jan 2012, 13:54

Re: [Bug] Dropping creature causes Ogre exception

Postby DunmerLord » 09 Aug 2013, 19:55

You are right Paul, sorry. I tested my code, then I did a pull to get the last changes before committing and I didn't test again.

Well, thank you guys. I'll try to keep working on this project in any spare time I have.
DunmerLord
 
Posts: 13
Joined: 19 Jul 2013, 17:48

Re: [Bug] Dropping creature causes Ogre exception

Postby paul424 » 09 Aug 2013, 20:24

I mean , I don't say that was you , it might be mine fault when I uploaded XML files ... :)
User avatar
paul424
OD Moderator
 
Posts: 660
Joined: 24 Jan 2012, 13:54

Re: [Bug] Dropping creature causes Ogre exception

Postby DunmerLord » 09 Aug 2013, 20:53

I know man! You set a beginner's trap for me! :D
DunmerLord
 
Posts: 13
Joined: 19 Jul 2013, 17:48

Who is online

Users browsing this forum: No registered users and 1 guest