diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index 80248b8..67f4a75 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -365,7 +365,13 @@ struct phys2d_poly *Make2DPoly(int go) float phys2d_poly_moi(struct phys2d_poly *poly, float m) { - return cpMomentForPoly(m, arrlen(poly->points), poly->points, cpvzero, poly->radius); + float moi = cpMomentForPoly(m, arrlen(poly->points), poly->points, cpvzero, poly->radius); + if (moi <= 0) { + YughError("Polygon MOI is negative. Returning one;"); + return 1; + } + + return moi; } void phys2d_polydel(struct phys2d_poly *poly) diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index 0e8719e..76ffa57 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -117,6 +117,11 @@ void gameobject_apply(struct gameobject *go) cpBodyEachShape(go->body, go_shape_apply, go); if (go->bodytype == CP_BODY_TYPE_DYNAMIC) cpBodySetMass(go->body, go->mass); + + if (cpBodyGetMoment(go->body) <= 0.f) { + YughError("Moment for object %d is zero. Setting to one.", go2id(go)); + cpBodySetMoment(go->body, 1.f); + } } static void gameobject_setpickcolor(struct gameobject *go)