Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Freeing a RigidBody2D containing an Area2D node triggers an error condition #95

Open
gkunter opened this issue Dec 28, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@gkunter
Copy link

gkunter commented Dec 28, 2023

Describe the bug

Calling queue_free() on a RigidBody2D node that has an Area2D child triggers an error condition:

E 0:00:02:0238   on_body_exit: Condition "foundIt == detected_bodies.end()" is true.
  <C++ Source>   src/bodies/box2d_area_2d.cpp:63 @ on_body_exit()

This message is repeated several times when trying to free the RigidBody2D. The number of times appears to be related to the number of physics-relevant child nodes of the body. In larger projects, the error log easily gets spammed by hundreds of messages.

While the RigidBody2D is still removed from the scene tree (at least, it's not visible in the "Remote" view anymore), it is unclear to me whether the current behavior may cause memory leaks as the queue_free() call might not be completed fully.

To Reproduce

To reproduce, the following scene RigidBody will be used:

RigidBody: RigidBody2D
    RigidBodyShape: CollisionShape2D
    Area: Area2D
        AreaShape: CollisionShape2D

Screenshot_20231228_105746

This scene is added as a child to the project's main scene:

Main: Node2D
TestBody: RigidBody

Screenshot_20231228_110037

The script attached to this main scene will try to call queue_free() on TestBody if SPACE is pressed:

# main.gd
extends Node2D


func _input(ev: InputEvent):
    if ev.is_action_pressed("ui_accept"):
        $TestBody.queue_free()

When running this scene and pressing SPACE, the error condition "foundIt == detected_bodies.end()" is true. is triggered three times.

Expected behavior

Calling queue_free() on a RigidBody2D node should not trigger an error condition if the node contains an Area2D child. node

Project
The reproducible minimal project described above is attached as a file (including Box2D as an installed add-on):

Box2DAreaRemove.zip

Versions (please complete the following information):

  • OS: Kubuntu 22.04.3
  • Godot 4.2.1
  • Box2d 0.9.9
@gkunter gkunter added the bug Something isn't working label Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant