Skip to content

Commit e78d54e

Browse files
committed
Hotfix: Fracture/CutFracture.gd pools were not freed on exit game
1 parent 7e4d6e7 commit e78d54e

File tree

5 files changed

+65
-5
lines changed

5 files changed

+65
-5
lines changed

demo/src/CutFracture.gd

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ func _input(event: InputEvent) -> void:
9595
_cut_line_enabled = true
9696

9797

98+
func _exit_tree() -> void:
99+
_pool_cut_visualizer.clearPoolInstant()
100+
_pool_fracture_shards.clearPoolInstant()
101+
102+
103+
98104

99105

100106
func calculateCutLine(cur_pos : Vector2, t : float) -> void:
@@ -213,26 +219,33 @@ func cutSourcePolygons(cut_pos : Vector2, cut_shape : PoolVector2Array, cut_rot
213219

214220

215221
for shape in cut_fracture_info.shapes:
222+
var area_p : float = shape.area / total_area
216223
var spawn_pos : Vector2 = _source_polygon_parent.to_global(shape.centroid) + shape.world_pos
217-
var mass : float = s_mass * (shape.area / total_area)
224+
var mass : float = s_mass * area_p
218225
var dir : Vector2 = (spawn_pos - cut_pos).normalized()
219226

220-
call_deferred("spawnRigibody2d", shape.centered_shape, spawn_pos, 0.0, source.modulate, s_lin_vel + dir * cut_force, s_ang_vel, mass, cut_pos)
227+
# var texture_info : Dictionary = source.getTextureDetails()
228+
# var texture_offset : Vector2 = source.to_global(shape.centroid) - source.global_position
229+
#
230+
# texture_info.offset += texture_offset
231+
# texture_info.rot += source.global_rotation
232+
call_deferred("spawnRigibody2d", shape.centered_shape, spawn_pos, 0.0, source.modulate, s_lin_vel + dir * cut_force, s_ang_vel, mass, cut_pos)#,texture_info)
221233

222234
source.queue_free()
223235

224236

225237

226-
227-
func spawnRigibody2d(new_poly : PoolVector2Array, spawn_pos : Vector2, spawn_rot : float, color : Color, lin_vel : Vector2, ang_vel : float, mass : float, cut_pos : Vector2) -> void:
238+
func spawnRigibody2d(new_poly : PoolVector2Array, spawn_pos : Vector2, spawn_rot : float, color : Color, lin_vel : Vector2, ang_vel : float, mass : float, cut_pos : Vector2) -> void:#, texture_info : Dictionary) -> void:
228239
var instance = rigidbody_template.instance()
229240
_source_polygon_parent.add_child(instance)
230241
instance.global_position = spawn_pos
242+
instance.global_rotation = spawn_rot
231243
instance.set_polygon(new_poly)
232244
instance.modulate = color
233245
instance.linear_velocity = lin_vel# + (spawn_pos - cut_pos).normalized() * 50
234246
instance.angular_velocity = ang_vel
235247
instance.mass = mass
248+
# instance.setTexture(texture_info)
236249

237250

238251
func spawnFractureBody(fracture_shard : Dictionary, source_node) -> void:

demo/src/Fracture.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ func _input(event: InputEvent) -> void:
7676
_timer.start(3.0)
7777

7878

79+
func _exit_tree() -> void:
80+
_pool_fracture_bodies.clearPoolInstant()
7981

8082

8183
func fractureAll() -> void:

demo/src/RigidBody2D.gd

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ onready var _col_polygon2d := $CollisionPolygon2D
1313
onready var _rng := RandomNumberGenerator.new()
1414

1515

16+
1617
func _ready() -> void:
1718
_rng.randomize()
1819
var poly = PolygonLib.createCirclePolygon(radius, smoothing)
1920
setPolygon(poly)
20-
2121
linear_velocity = Vector2.RIGHT.rotated(PI * 2.0 * _rng.randf()) * _rng.randf_range(rand_linear_velocity_range.x, rand_linear_velocity_range.y)
2222
# angular_velocity = _rng.randf_range(rand_angular_velocity_range.x, rand_angular_velocity_range.y)
2323

@@ -33,6 +33,17 @@ func setPolygon(poly : PoolVector2Array) -> void:
3333
_line2d.points = poly
3434

3535

36+
#func setTexture(texture_info : Dictionary) -> void:
37+
# _polygon2d.texture = texture_info.texture
38+
# _polygon2d.texture_scale = texture_info.scale
39+
# _polygon2d.texture_offset = texture_info.offset
40+
# _polygon2d.texture_rotation = texture_info.rot
41+
#
42+
#
43+
#func getTextureDetails() -> Dictionary:
44+
# return {"texture" : _polygon2d.texture, "rot" : _polygon2d.texture_rotation, "offset" : _polygon2d.texture_offset, "scale" : _polygon2d.texture_scale}
45+
46+
3647
func getPolygon() -> PoolVector2Array:
3748
return _polygon2d.get_polygon()
3849

demo/tile-test-01.png

8.1 KB
Loading

demo/tile-test-01.png.import

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/tile-test-01.png-1c21d1c8fcc88a909d68f7011b7512d1.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://demo/tile-test-01.png"
13+
dest_files=[ "res://.import/tile-test-01.png-1c21d1c8fcc88a909d68f7011b7512d1.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=1
23+
flags/filter=true
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
stream=false
32+
size_limit=0
33+
detect_3d=true
34+
svg/scale=1.0

0 commit comments

Comments
 (0)