Skip to content

GDScript: Fix and simplify coroutine stack clearing#117053

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
dalexeev:gds-fix-coroutine-stack-clearing
Mar 12, 2026
Merged

GDScript: Fix and simplify coroutine stack clearing#117053
Repiteo merged 1 commit into
godotengine:masterfrom
dalexeev:gds-fix-coroutine-stack-clearing

Conversation

@dalexeev
Copy link
Copy Markdown
Member

@dalexeev dalexeev commented Mar 4, 2026

This PR simplifies coroutine stack clearing. When a coroutine resumed, the stack was previously stored in multiple GDScriptFunctionStates (via the Ref<GDScriptFunctionState> first_state; field).

Now, previous GDScriptFunctionStates are no longer held in memory. After a suspended function resumes, responsibility for the stack passes to GDScriptFunction::call(), which cleans it up at the end as usual.

The first_state field was introduced in #19828. I made sure that this change doesn't reintroduce #19823:

extends Node

func _ready():
    while true:
        await get_tree().process_frame
        await get_tree().process_frame
        await get_tree().process_frame
        var a: PackedByteArray
        var b := RefCounted.new()
        print("await 3 idle frames ", Performance.get_monitor(Performance.OBJECT_COUNT))

Before, it was previous_state, introduced in #17291. I made sure that this change doesn't reintroduce #17280:

extends Node

func _ready():
    await test()
    print("ready is over")

func test():
    await $Button.pressed
    await $Button2.pressed

@Repiteo Repiteo merged commit 4e34c6e into godotengine:master Mar 12, 2026
20 checks passed
@Repiteo
Copy link
Copy Markdown
Contributor

Repiteo commented Mar 12, 2026

Thanks!

@dalexeev dalexeev deleted the gds-fix-coroutine-stack-clearing branch March 12, 2026 14:31
@stuartcarnie
Copy link
Copy Markdown
Contributor

@dalexeev I can confirm it resolves the issues with the MRP in #117339. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants