Skip to content
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

'duplicate()' error message + corruption #102573

Open
EmilyV99 opened this issue Feb 8, 2025 · 4 comments
Open

'duplicate()' error message + corruption #102573

EmilyV99 opened this issue Feb 8, 2025 · 4 comments

Comments

@EmilyV99
Copy link

EmilyV99 commented Feb 8, 2025

Tested versions

v4.4.beta1.official [d33da79]
v4.4.beta2.official [a013481]
v4.4.beta3.official [06acfcc]

System information

Godot v4.4.beta3 - Windows 10 (build 19045) - Multi-window, 1 monitor - Vulkan (Mobile) - dedicated AMD Radeon RX 6600 (Advanced Micro Devices, Inc.; 32.0.11027.2001) - AMD Ryzen 5 3600 6-Core Processor (12 threads)

Issue description

For a transition effect I have between two scenes, I create a duplicate of my entire player character.

Issue # 1 with this (random error message, appears to occur whenever this code duplicates the player. No idea why it happens.)

Image

Issue # 2: Only under some circumstances (it appears to be after I've died and respawned; but, the only thing that does that should be relevant is it frees the player character, then re-instantiates it from its' scene again...), duplicating the player results in a quite corrupted duplicate.

Normal looking:
Image

Corrupted:
Image

I have no clue what's wrong here, all I'm doing is calling duplicate() and expecting it to create a duplicate. Will add more details if I manage to find any, but I've been bashing my head at this for hours and making no further headway.

Steps to reproduce

I have no idea how to easily reproduce it, it isn't even every time I duplicate the player in the code. Duplicating it in other places sometimes works fine. I would expect a timing issue of some sort, but even placing everything related to the issue in a lambda and then using call_deferred on that lambda to delay it all creates an identical result.

Minimal reproduction project (MRP)

Wish I could reproduce it simpler....

@Invium-GH
Copy link

Comes across to me as a sort of 'race' condition in your code. As in, the character is being duplicated while it is also being freed. This could also explain the corruption, as the duplication might then reference stale or corrupted data. One possible workaround in your code would be to add a boolean which you toggle before and after duplication.

To then add a check on the code that calls the free. Only freeing it when it is not being duplicated. So the two processes, the duplication and the freeing do not accidentally get called simultaneously.

@EmilyV99
Copy link
Author

EmilyV99 commented Feb 8, 2025

Comes across to me as a sort of 'race' condition in your code. As in, the character is being duplicated while it is also being freed. This could also explain the corruption, as the duplication might then reference stale or corrupted data. One possible workaround in your code would be to add a boolean which you toggle before and after duplication.

To then add a check on the code that calls the free. Only freeing it when it is not being duplicated. So the two processes, the duplication and the freeing do not accidentally get called simultaneously.

The duplicate is not freed early. Note that in the above images, the transition animation (ellipse expanding, fading between two scenes) is still playing- the duplicate will not be freed until after the entire animation finishes via the tween.

I just placed a breakpoint on the duplicate() call. The errors here occur DURING the duplicate call itself, as they appear when I step over just that one line, with the queue_free on the duplicate not having any chance to run yet.

Image

Also, to be clear, the ORIGINAL character is not being freed whatsoever as part of this transition.

@Invium-GH
Copy link

Also, to be clear, the ORIGINAL character is not being freed whatsoever as part of this transition.

I didn't mean it as an insult of your code, or anything like that. I simply have no access to the code. So, couldn't be sure you weren't pushing the engine to its breaking point. I've done that myself.

Anyhow, thanks for the additional information. Something peculiar does indeed seem to be going on.

@matheusmdx
Copy link
Contributor

From the error message this looks like a duplicate of #96246, in this case the error only appears when duplicating a node with internal child nodes (the internal nodes wasn't being duplicated and raise the child count difference error).

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

No branches or pull requests

4 participants