From 399797d0b1cc4c720c047482b81df67bf24a35a7 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 4 Jan 2020 21:06:46 +0100 Subject: [PATCH] physics: fix assertions when particles get very large positions Fixes #822 --- doc/ReleaseNotes | 1 + panda/src/physics/linearFrictionForce.cxx | 3 +-- panda/src/physics/linearNoiseForce.cxx | 13 ++++--------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/doc/ReleaseNotes b/doc/ReleaseNotes index 17a153f6e6..a89062a341 100644 --- a/doc/ReleaseNotes +++ b/doc/ReleaseNotes @@ -8,6 +8,7 @@ This is a recommended bugfix release, especially for macOS users. * macOS thirdparty packages are now linked with libc++ (#584) * Homebrew Python should now locate Panda libraries correctly (#755) * Work around Tk bug cancelling Load Params in Particle Panel on macOS (#811) +* Fix NaN assertions when particles get very large positions (#822) * Add support for Autodesk Maya 2020 * Fix maya2egg erroring when running from a pip installation (#709) * Support .pz and .gz compressed models in deployment system diff --git a/panda/src/physics/linearFrictionForce.cxx b/panda/src/physics/linearFrictionForce.cxx index 78ebd3d0c4..c953568390 100644 --- a/panda/src/physics/linearFrictionForce.cxx +++ b/panda/src/physics/linearFrictionForce.cxx @@ -61,8 +61,7 @@ get_child_vector(const PhysicsObject* po) { physics_debug(" v "<get_position(); // get all of the components - int int_x, int_y, int_z; + PN_stdfloat int_x, int_y, int_z; PN_stdfloat frac_x, frac_y, frac_z; - int_x = (int) p[0]; - frac_x = p[0] - int_x; - - int_y = (int) p[1]; - frac_y = p[1] - int_y; - - int_z = (int) p[2]; - frac_z = p[2] - int_z; + frac_x = std::modf(p[0], &int_x); + frac_y = std::modf(p[1], &int_y); + frac_z = std::modf(p[2], &int_z); // apply the cubic smoother to the fractional values PN_stdfloat cubic_x, cubic_y, cubic_z;