Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime crash when calling KinematicBody3D.move_and_slide with Bullet physics #40840

Closed
briansemrau opened this issue Jul 29, 2020 · 6 comments · Fixed by #42639
Closed

Runtime crash when calling KinematicBody3D.move_and_slide with Bullet physics #40840

briansemrau opened this issue Jul 29, 2020 · 6 comments · Fixed by #42639

Comments

@briansemrau
Copy link
Contributor

Godot version:

Godot v4.0.dev.custom_build. 7b17cd2

(Issue introduced in v4.0.dev.custom_build. 3e87022)

OS/device including version:

Windows 10 (v1903)

Issue description:

Calling function move_and_slide within KinematicBody3D physics process causes a runtime crash.
This issue was introduced in #40252.

CrashHandlerException: Program crashed
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[0] btCollisionShape::getShapeType (C:\Users\brian\Documents\GitHub\godot\thirdparty\bullet\BulletCollision\CollisionShapes\btCollisionShape.h:108)
[1] btCollisionShape::isConvex (C:\Users\brian\Documents\GitHub\godot\thirdparty\bullet\BulletCollision\CollisionShapes\btCollisionShape.h:71)
[2] SpaceBullet::test_body_motion (C:\Users\brian\Documents\GitHub\godot\modules\bullet\space_bullet.cpp:1021)
[3] BulletPhysicsServer3D::body_test_motion (C:\Users\brian\Documents\GitHub\godot\modules\bullet\bullet_physics_server.cpp:863)
[4] KinematicBody3D::move_and_collide (C:\Users\brian\Documents\GitHub\godot\scene\3d\physics_body_3d.cpp:922)
[5] KinematicBody3D::move_and_slide (C:\Users\brian\Documents\GitHub\godot\scene\3d\physics_body_3d.cpp:983)
[6] MethodBind6R<KinematicBody3D,Vector3,Vector3 const &,Vector3 const &,bool,int,float,bool>::call (C:\Users\brian\Documents\GitHub\godot\core\method_bind_ext.gen.inc:421)
[7] Object::call (C:\Users\brian\Documents\GitHub\godot\core\object.cpp:797)
[8] Variant::call_ptr (C:\Users\brian\Documents\GitHub\godot\core\variant_call.cpp:1255)
[9] GDScriptFunction::call (C:\Users\brian\Documents\GitHub\godot\modules\gdscript\gdscript_function.cpp:1068)
[10] GDScriptInstance::call (C:\Users\brian\Documents\GitHub\godot\modules\gdscript\gdscript.cpp:1304)
[11] ScriptInstance::call (C:\Users\brian\Documents\GitHub\godot\core\script_language.cpp:308)
[12] Node::_notification (C:\Users\brian\Documents\GitHub\godot\scene\main\node.cpp:64)
[13] Node::_notificationv (C:\Users\brian\Documents\GitHub\godot\scene\main\node.h:46)
[14] Node3D::_notificationv (C:\Users\brian\Documents\GitHub\godot\scene\3d\node_3d.h:52)
[15] CollisionObject3D::_notificationv (C:\Users\brian\Documents\GitHub\godot\scene\3d\collision_object_3d.h:38)
[16] PhysicsBody3D::_notificationv (C:\Users\brian\Documents\GitHub\godot\scene\3d\physics_body_3d.h:41)
[17] KinematicBody3D::_notificationv (C:\Users\brian\Documents\GitHub\godot\scene\3d\physics_body_3d.h:261)
[18] Object::notification (C:\Users\brian\Documents\GitHub\godot\core\object.cpp:808)
[19] SceneTree::_notify_group_pause (C:\Users\brian\Documents\GitHub\godot\scene\main\scene_tree.cpp:820)
[20] SceneTree::iteration (C:\Users\brian\Documents\GitHub\godot\scene\main\scene_tree.cpp:412)
[21] Main::iteration (C:\Users\brian\Documents\GitHub\godot\main\main.cpp:2339)
[22] OS_Windows::run (C:\Users\brian\Documents\GitHub\godot\platform\windows\os_windows.cpp:627)
[23] widechar_main (C:\Users\brian\Documents\GitHub\godot\platform\windows\godot_windows.cpp:163)
[24] _main (C:\Users\brian\Documents\GitHub\godot\platform\windows\godot_windows.cpp:185)
[25] main (C:\Users\brian\Documents\GitHub\godot\platform\windows\godot_windows.cpp:199)
[26] __scrt_common_main_seh (d:\A01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[27] BaseThreadInitThunk
-- END OF BACKTRACE --

This crash is caused by a nullptr in SpaceBullet::test_body_motion because CollisionObjectBullet::ShapeWrapper.bt_shape has not yet been initialized by ShapeWrapper::claim_bt_shape

Steps to reproduce:
See above.

Minimal reproduction project:

BulletShapeNullptrCrash.zip

@briansemrau briansemrau changed the title Runtime crash when calling KinematicBody3D.move_and_slide Runtime crash when calling KinematicBody3D.move_and_slide with Bullet physics Jul 29, 2020
@briansemrau
Copy link
Contributor Author

Probably not useful for anyone, but this is temporarily fixed by adding small delay before move_and_slide is called

func _physics_process(delta):
    if _time_passed > 0.1:
        move_and_slide(...)

@AndreaCatania
Copy link
Contributor

This fix the issue: #41067, can you please test it?

@briansemrau
Copy link
Contributor Author

This fix the issue: #41067, can you please test it?

#41067 fixes the issue of calling test_body_motion on the first frame that the kinematic body is created, but I'm still getting other crashes in my own test project. I'll see if this second issue is already reported.

@AndreaCatania
Copy link
Contributor

@briansemrau thanks, don't forget to tag me please, so I don't lost it.

@briansemrau
Copy link
Contributor Author

briansemrau commented Aug 6, 2020

Finally reproduced the issue I mentioned. I'm putting it here instead of in a new issue because I believe it's closely related.

When removing/readding shapes while calling KinematicBody3D.move_and_slide, the game crashes because of a pure virtual call on btCollisionShape. Without the call to test_body_motion there is no issue. This may be the same issue as #40311 (see #40311 (comment))
EDIT: This crash only occurs when the KinematicBody3D and StaticBody3D begin to collide.

Here's the script that causes it:

# Snippet from main scene
func _physics_process(delta):
	if _flag:
		# _collshp is the CollisionShape3D of a static body
		_collshp.shape = null
		_flag = false
	else:
		_collshp.shape = BoxShape3D.new()
		_flag = true

MRP:
BulletCrashAddBodyTestMotion.zip

And here's the call stack:

>	godot.windows.tools.64.exe!_purecall() Line 29	C++
 	godot.windows.tools.64.exe!btCollisionShape::getBoundingSphere(btVector3 & center, float & radius) Line 38	C++
 	godot.windows.tools.64.exe!btCollisionShape::getAngularMotionDisc() Line 53	C++
 	godot.windows.tools.64.exe!btContinuousConvexCollision::calcTimeOfImpact(const btTransform & fromA, const btTransform & toA, const btTransform & fromB, const btTransform & toB, btConvexCast::CastResult & result) Line 103	C++
 	godot.windows.tools.64.exe!btCollisionWorld::objectQuerySingleInternal(const btConvexShape * castShape, const btTransform & convexFromTrans, const btTransform & convexToTrans, const btCollisionObjectWrapper * colObjWrap, btCollisionWorld::ConvexResultCallback & resultCallback, float allowedPenetration) Line 636	C++
 	godot.windows.tools.64.exe!btCollisionWorld::objectQuerySingle(const btConvexShape * castShape, const btTransform & convexFromTrans, const btTransform & convexToTrans, btCollisionObject * collisionObject, const btCollisionShape * collisionShape, const btTransform & colObjWorldTransform, btCollisionWorld::ConvexResultCallback & resultCallback, float allowedPenetration) Line 610	C++
 	godot.windows.tools.64.exe!btSingleSweepCallback::process(const btBroadphaseProxy * proxy) Line 1072	C++
 	godot.windows.tools.64.exe!BroadphaseRayTester::Process(const btDbvtNode * leaf) Line 237	C++
 	godot.windows.tools.64.exe!btDbvt::rayTestInternal<BroadphaseRayTester>(const btDbvtNode * root, const btVector3 & rayFrom, const btVector3 & rayTo, const btVector3 & rayDirectionInverse, unsigned int * signs, float lambda_max, const btVector3 & aabbMin, const btVector3 & aabbMax, btAlignedObjectArray<btDbvtNode const *> & stack, BroadphaseRayTester & policy) Line 1270	C++
 	godot.windows.tools.64.exe!btDbvtBroadphase::rayTest(const btVector3 & rayFrom, const btVector3 & rayTo, btBroadphaseRayCallback & rayCallback, const btVector3 & aabbMin, const btVector3 & aabbMax) Line 274	C++
 	godot.windows.tools.64.exe!btCollisionWorld::convexSweepTest(const btConvexShape * castShape, const btTransform & convexFromWorld, const btTransform & convexToWorld, btCollisionWorld::ConvexResultCallback & resultCallback, float allowedCcdPenetration) Line 1103	C++
 	godot.windows.tools.64.exe!SpaceBullet::test_body_motion(RigidBodyBullet * p_body, const Transform & p_from, const Vector3 & p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult * r_result, bool p_exclude_raycast_shapes) Line 1052	C++
	...

@AndreaCatania
Copy link
Contributor

Fixes both crashes: #41096

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment