How not to use casts [an ironical comment]
Posted: Sat Jan 02, 2016 9:59 pm
Recently I spent some time in Orxonox, when I noticed something strange:
Only that, for some reason, one healthbar is blurred and the other is not.
Ok well, but what's up with that other thing over here: Is that... a giant healthbar?
That must be one moth**fu**ing healthy portal!
But wait... aren't portals supposed to be things? Like... objects? Without health?
So let's check the code: So uhm... apparently every WorldEntity is now a Pawn and can be safely converted with a C-style-cast?
Well, nope.
So I fixed it with an orxonox_cast (which is basically the same like a dynamic_cast): And now portals look correctly (without a healthbar): What do we learn from that? Never use C-style-casts!
(I already knew that!)
By the way, did you know that portals will also teleport your laser beams (and other projectiles)? It's pretty cool:
What's that weird blurry thing on the left? Apparently it's supposed to be a health bar, just like the one on the right.Only that, for some reason, one healthbar is blurred and the other is not.
Ok well, but what's up with that other thing over here: Is that... a giant healthbar?
That must be one moth**fu**ing healthy portal!
But wait... aren't portals supposed to be things? Like... objects? Without health?
So let's check the code: So uhm... apparently every WorldEntity is now a Pawn and can be safely converted with a C-style-cast?
Well, nope.
So I fixed it with an orxonox_cast (which is basically the same like a dynamic_cast): And now portals look correctly (without a healthbar): What do we learn from that? Never use C-style-casts!
(I already knew that!)
By the way, did you know that portals will also teleport your laser beams (and other projectiles)? It's pretty cool: