Skip to content

fix(mcp): Resolve add_node resource leak and duplication issues #19

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

alienfrenZyNo1
Copy link

Fix add_node Resource Leak and Duplication Issues

This PR addresses issues encountered when using the add_node MCP tool, which relies on the godot_operations.gd script running in headless mode.

Problem:

  1. RID Allocation Leak: The script initially caused RID allocations of type 'PN13RendererDummy14TextureStorage12DummyTextureE' were leaked at exit errors, likely due to the instantiated scene root not being freed.
  2. Node Duplication: Attempting to fix the leak by freeing the scene root (scene_root.free()) resulted in duplicate nodes being added to the saved scene file. This might be due to freeing the node before the ResourceSaver.save() operation fully completed in the headless environment.
  3. RefCounted Error: Incorrectly attempting to free the PackedScene resource caused "Can't free a RefCounted object" errors.

Solution:

  • The add_node function in src/scripts/godot_operations.gd has been modified:
    • The scene_root.free() call is reinstated to prevent the RID leak.
    • A small delay (OS.delay_msec(100)) is introduced after ResourceSaver.save() and before scene_root.free(). This allows the save operation sufficient time to complete before the instantiated scene is freed, preventing the node duplication issue.
    • The incorrect attempt to free the PackedScene was removed earlier in the debugging process.

Verification:

  • Tested the add_node tool after these changes.
  • Confirmed that the RID leak error no longer occurs.
  • Verified by reading the target scene file (.tscn) that the node is added correctly without duplicates.

Coding-Solo and others added 19 commits March 8, 2025 23:33
…cript-approach

Feature/bundled gdscript approach
…id-support

Changed Godot tooling to make use of Godot 4 API
Added Debug mode, which adds additional tests and logging to Godot tools
Added tools related to 4.4's uid files for scripts and resources
other fixes and changes
…hing

Implement robust pathing with improved validation
Modified godot_operations.gd to add a delay before freeing the instantiated scene root, preventing both RID leaks and node duplication.
- Make JSON param optional in godot_operations.gd _init
- Add explicit param validation in GDScript functions
- Add delay before quit() in GDScript for potential buffer flush
- Infer resave_resources success via exit code & stderr in index.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants