@@ -176,14 +176,16 @@ func _draw() -> void:
176176
177177
178178# Logic
179-
180179func _setup (run_reset : bool = true ) -> void :
181180 if not is_inside_tree ():
182181 return
183182
184- _points .resize (num_segments + 1 )
185- _oldpoints .resize (num_segments + 1 )
186- _resize_with_default (_simulation_weights , num_segments + 1 , 1.0 )
183+ var num_points := num_segments + 1
184+
185+ # Initialize all new points with the endpoint's coordinates to reduce erratic movement.
186+ _resize_with_default (_points , num_points , _points [- 1 ] if not _points .is_empty () else Vector2 .ZERO )
187+ _resize_with_default (_oldpoints , num_points , _oldpoints [- 1 ] if not _oldpoints .is_empty () else Vector2 .ZERO )
188+ _resize_with_default (_simulation_weights , num_points , 1.0 )
187189
188190 update_colors ()
189191 update_segments ()
@@ -444,9 +446,11 @@ func _set_seg_dist(value: Curve) -> void:
444446 update_segments ()
445447
446448
447- func _resize_with_default (arr : PackedFloat32Array , new_size : int , default : float ) -> void :
448- var oldsize := arr .size ()
449- arr .resize (new_size )
449+ static func _resize_with_default (array : Variant , new_size : int , default : Variant ) -> void :
450+ @warning_ignore ("unsafe_method_access" )
451+ var oldsize : int = array .size ()
452+ @warning_ignore ("unsafe_method_access" )
453+ array .resize (new_size )
450454
451455 for i in range (oldsize , new_size ):
452- arr [i ] = default
456+ array [i ] = default
0 commit comments