GarageGames / Torque2D

MIT Licensed Open Source version of Torque 2D game engine from GarageGames
MIT License
1.67k stars 1.56k forks source link

Sprites with Zero Width or Height Cause Assertion Failure #297

Closed greenfire27 closed 8 years ago

greenfire27 commented 8 years ago

This is pretty easy to repeat and could easily happen in games - especially with the new growTo code. All you need is to turn on object input events on a window and then give an object 0 width or height. Then just roll your mouse over the location when the object should be and you'll get the assertion error.

To test, open the sandbox and run these commands with the truck toy running.

TruckToy.TruckBody.setSizeX(0);
sandboxWindow.setUseObjectInputEvents(true);

Now close the console and move your pointer over the place where the truck is hiding. You can ignore the assertion if you want to keep going.

The assertion fires from inside the box2D code which we are trying not to change. So the trick is to work far enough back that we can check to see if an object has area (i.e. width > 0 and height > 0) and and skip the object if it doesn't.

Until we fix it, you can work around this error by simply disabling an object if it has no area.

MichPerry-GG commented 8 years ago

Just my opinion, but I think this is the very reason assertion errors exist. If my object's dimensions were set to zero, I want to know about it ASAP. If the object is skipped, then I could have very difficult bug to track down. The work around is actually a valid approach for developers that DO want to skip malformed objects.

greenfire27 commented 8 years ago

You have a valid argument, but the assertion isn't checking to see if you have an object with 0 width or height and so the error it pops up is not helpful. Additionally you're assuming an object with 0 width or height is a malformed object. In my case I had a progress bar sprite that was throwing the assert when the progress was zero. I could also imagine a case where an object flips using GrowTo. Negative width flips the object similar to the flipX() method. GrowTo could be used to make the object flip over for a neat effect. Of course if your mouse is over the object when it passes through zero width the assert would fire.

Anyway, I think the biggest thing is that the average user would find this assert cryptic instead of helpful. I know I did.

greenfire27 commented 8 years ago

Resolved. Objects with no area are treated as invisible by the picking class.