Game Development Community

TVector empty isn't clear

by James Spellman · in Torque Game Engine · 08/26/2006 (5:42 pm) · 4 replies

This is a rant/bug report. Be prepared...

I was experiencing some strange crashes that turned out to be my fault because I misinterpreted the purpose of a the tVector method empty(). The bool empty() method checks to see if the element count is zero. It does not, as I would later come to understand, empty the vector like I assumed it would. I should have been using the clear() method all along. My bad.

I wish empty it was named a better. Would isEmpty have been so hard to think of? But it is the standard name, as far as I remember, so I guess we're stuck with it. Yup. Double-checked my STL Reference.

Anyway, so who else has fallen into this little trap? Well, fxShapeReplicator, around line 482 seems to be the only one I can find. It's that way in TSE too.

Edit: Go nuts with Markups and you're bound to make a mistake eventually.

#1
08/26/2006 (9:41 pm)
I have hit this issue myself in the past, but it's like that for a reason. tVector tries to mimic STL vector... which also has empty() and clear(). I've gotten used to it and usually wait for the code tip to popup in the IDE when i forget.
#2
08/28/2006 (11:40 am)
To highlight the problem, here's the code from fxShapeReplicator::DestroyShapes:

// Empty the Replicated Shapes Vector.
    mReplicatedShapes.empty();

should probably be:

// Clear the Replicated Shapes Vector.
    mReplicatedShapes.clear();
#3
10/25/2006 (9:30 am)
Bump

This is still in 1.5. If it's not a bug, I'll shut up. If it is, I'll hold my breath until I die and/or someone takes note.
#4
10/25/2006 (9:48 am)
It is def a bug if that is the code.
empty is returning a value not performing any other real tasks.

so calling it and not using the return is useless.
so I am sure the intent would have been to "empty" the array :)
he should have been thinking "clear" not empty :)

stupid function anyhow that empty.. what a pos.
why not, isempty? or something? wtf..