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

Fix multiple recent Bullet physics crashing issues. #41082

Closed
wants to merge 5 commits into from

Conversation

madmiraal
Copy link
Contributor

@madmiraal madmiraal commented Aug 6, 2020

Fixes #40311
Fixes #40840

As elaborated on here and here, #39726 has caused multiple crashing issues (such as #40311 and #40840) which are not being fully resolved with #40252 (see comment) #40886 or #41067 (see comment) Furthermore, it did not solve #30027 for which it was created. Therefore this PR reverts #39726, which also requires reverting #40252.

Note: This PR also includes three additional commits:

  1. Improves [Bullet] Area zero gravity with Bullet #40127 (using the change from Call reload_space_override_modificator() directly when processing a body entering or leaving an area. #40186) instead of Improved Bullet Physics flush algorithm, Lazy collision filter reload, Shape reload regression fix. #40252.
  2. The fix for [Bullet] Gravity is applied to RigidBody even with custom_integrator turned on #40508 included in Improved Bullet Physics flush algorithm, Lazy collision filter reload, Shape reload regression fix. #40252; but extended to include dampening.
  3. A fix for Fixes leak when creating bullet shape #41040 that also relied on a Optimized physics object spawn time #39726.

Finally I've confirmed it does not revert the fix for #40506.

@AndreaCatania
Copy link
Contributor

AndreaCatania commented Aug 7, 2020

The benchmark code is this:

extends Node

var count = 0

var shapes_per_frame := 2000
var shape := BoxShape3D.new()
var t1

func _ready():
	t1 = OS.get_ticks_msec()
	_do_test()

func _physics_process(delta):
	if count < 3:
		var t2 = OS.get_ticks_msec()
		count += 1
		print("Frame ", count, ": ", t2 - t1, "ms")
	else:
		get_tree().quit()

func _do_test():
	print("Test start")
	for i in range(0, shapes_per_frame):
		var rb = RigidBody3D.new()
		var c = CollisionShape3D.new()
		c.set_shape(shape)
		rb.add_child(c)
		add_child(rb)
		if i % 50 == 0:
			print("Added: ", i)

This is the benchmark result obtained from this PR on my pc:

Test start
Added: 0
Added: 50
Added: 100
Added: 150
Added: 200
Added: 250
Added: 300
Added: 350
Added: 400
Added: 450
Added: 500
Added: 550
Added: 600
Added: 650
Added: 700
Added: 750
Added: 800
Added: 850
Added: 900
Added: 950
Added: 1000
Added: 1050
Added: 1100
Added: 1150
Added: 1200
Added: 1250
Added: 1300
Added: 1350
Added: 1400
Added: 1450
Added: 1500
Added: 1550
Added: 1600
Added: 1650
Added: 1700
Added: 1750
Added: 1800
Added: 1850
Added: 1900
Added: 1950
Frame 1: 8618ms
Frame 2: 22686ms
Frame 3: 34715ms

This is the result obtained using the current master branch:

Test start
Added: 0
Added: 50
Added: 100
Added: 150
Added: 200
Added: 250
Added: 300
Added: 350
Added: 400
Added: 450
Added: 500
Added: 550
Added: 600
Added: 650
Added: 700
Added: 750
Added: 800
Added: 850
Added: 900
Added: 950
Added: 1000
Added: 1050
Added: 1100
Added: 1150
Added: 1200
Added: 1250
Added: 1300
Added: 1350
Added: 1400
Added: 1450
Added: 1500
Added: 1550
Added: 1600
Added: 1650
Added: 1700
Added: 1750
Added: 1800
Added: 1850
Added: 1900
Added: 1950
Frame 1: 34ms
Frame 2: 8914ms
Frame 3: 13978ms

This is flame graph extracted from the perf of this PR:
Screenshot from 2020-08-07 09-43-54

This is flame graph extracted from the perf of master branch:
Screenshot from 2020-08-07 09-13-49

@madmiraal
Copy link
Contributor Author

Rebased following #42061.

@madmiraal
Copy link
Contributor Author

Superseded by #42639. I've created #42649 and #42650, and reopened #40186 and #40187 to address the issues addressed by this PR, but not addressed by #42639.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants