TreeIterator3D problem

nargil

02-03-2009 12:44:38

I'm trying to save trees in my editor. The thing is that the last tree is never saved. For example if I place 1 tree, save the scene, reload it, then there is no tree in the scene. If I place 2 trees then after reloading there is only 1. If I place 3 - after reloading i get only 2;

And it's not the loading part broken ;) Trees listed in the xml file are being loaded. There is just 1 missing in the file.


Forests::TreeIterator3D itT = this->drzewaLoader->getTrees();
Ogre::Vector3 pos;
while(itT.hasMoreElements())
{
TreeRef tree = itT.getNext();
TiXmlElement* treeXML = new TiXmlElement("Tree");
treeXML->SetAttribute("entity", tree.getEntity()->getMesh()->getName().c_str());
pos = tree.getPosition();
treeXML->SetDoubleAttribute("posX", pos.x);
treeXML->SetDoubleAttribute("posY", pos.y);
treeXML->SetDoubleAttribute("posZ", pos.z);
treeXML->SetDoubleAttribute("yaw", tree.getYaw().valueRadians());
treeXML->SetDoubleAttribute("scale", tree.getScale());

terenXML->LinkEndChild(treeXML);
}

NoodlesOnMyBack

03-03-2009 15:43:06

Probably a stab in the dark, but here: TreeRef tree = itT.getNext();
Isnt this stepping into the next tree before you read the first one? Maybe the first record is the one you miss.

nargil

03-03-2009 16:10:27

Probably a stab in the dark, but here: TreeRef tree = itT.getNext();
Isnt this stepping into the next tree before you read the first one? Maybe the first record is the one you miss.

Nah. There is no other method to retrieve treeref from iterator than peekNext and getNext. Even tried to edit the iterator adding a method getCurrent(). Calling it before the first getNext() crashes the application.

I'm sure it's the last one. I tested it by putting 3 trees in a line along the X axis, walked throught the iterator and the last (largest X value was missing). Then i put another tree with a small X value and a larger Z. Walked throught the iterator and there were only trees with the Z:0, and there was the tree that was missing before. The last tree (with the larger Z position) was missing though.

Tried to call TreeRef tree = itT.getNext(); once more after the while loop. It causes an exception. So I can say for sure there is always the last tree missing in the TreeIterator3D

Hackslash

21-04-2009 08:36:07

This seems to be a bug, i've got the same problem. If u iterate through all trees the last tree is missing. But if u call tree = itT->peekNext() after the iteration loop the last tree is saved in "tree". Well but if you have no trees at all (or create some trees and delete them all with deletetrees() ) the applications crashs when calling peekNext().

I hope this bug can be fixed.

icaromotta

09-05-2012 15:38:38

Until today there is this error!

:cry: :cry: :cry: :cry: :cry:


How to solve this? If I create 10 trees, this iterator gets just 9 trees. The last tree is not returned.

creation order:

2034.73, 0, -9814.26
-644.063, 0, -4790.67
7891.35, 0, -10428.5
433.119, 0, -6272.16
-4337.54, 0, -11286
-1737.85, 0, -12189.3
-3907.83, 0, 1013.21 /*****************************************************************************************************/
3429.3, 0, -10680.5
-4732.08, 0, -14174.7
9683.4, 0, 636.25


iterator returned

-4732.08, 647.503, -14174.7
-1737.85, 1054.35, -12189.3
-4337.54, 1200.36, -11286
3429.3, 655.882, -10680.5
7891.35, 203.452, -10428.5
2034.73, 1167.87, -9814.26
433.119, 1315.36, -6272.16
-644.063, 1100.49, -4790.67
9683.4, 1046.43, 636.249


In comment position not recovered.