c++ - Assertion failed : area > 1.19209 -
i'm getting weird error when run program uses box2d
unexpected because it's in file related project(unbuilt folder not linked project). obtained copy box2d
vs12
, built project , setup-ed project following tutorial here:https://www.youtube.com/watch?v=keclrfkygkw&list=plspw4asqyyymu3pfg9gxywspghnsmioaw&index=53
here's code:
void box::init(b2world* world, const glm::vec2& position, const glm::vec2& dimensions) { m_dimensions = dimensions; b2bodydef boxdef; boxdef.type = b2_dynamicbody; boxdef.position.set(position.x, position.y); m_body = world->createbody(&boxdef); b2polygonshape boxshape; boxshape.setasbox(position.x / 2.0f, position.y / 2.0f); b2fixturedef fixturedef; fixturedef.shape = &boxshape; fixturedef.density = 1.0f; fixturedef.friction = 0.3f; m_fixture = m_body->createfixture(&fixturedef); }
where i've called init()
:
b2vec2 gravity(0.0f, -9.8f); m_world = std::make_unique<b2world>(gravity); b2bodydef groundbodydef; groundbodydef.position.set(0.0f, -10.0f); b2body* groundbody = m_world->createbody(&groundbodydef); b2polygonshape groundshape; groundshape.setasbox(50.0f, 10.0f); groundbody->createfixture(&groundshape, 0.0f); box newbox; newbox.init(m_world.get(), glm::vec2(0.0f, 14.0f), glm::vec2(15.0f, 15.0f)); m_boxes.push_back(newbox);
the error printed on console:
assertion failed : area > 1.19209 2896e-07f, path_to_unbuild_box2d\box2d_v2.3.0\box2d\box2d\collision\shapes\b2 polygonshape.cpp, line 422
here's error occur (when click retry
) line 336 b2fixture.h
:
inline void b2fixture::getmassdata(b2massdata* massdata) const { m_shape->computemass(massdata, m_density); }
problem 1 fixed
boxshape.setasbox(dimensions.x / 2.0f, dimensions.y / 2.0f); ///instead of position.
the line of code that's failing is (as mentioned in "assertion failed" message):
b2assert(area > b2_epsilon);
it means polygon has puny size (look @ assertion, area less 1.192092896e-07f
, value 0.0000001192092896
, tiny).
likely boxshape
has invalid size. set breakpoint on line:
boxshape.setasbox(position.x / 2.0f, position.y / 2.0f);
and inspect value of position
. make sure you're setting box's dimensions sane value. bet aren't.
Comments
Post a Comment