-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Workaround on GodotSharp duplicate key exception when adding generic entries to ScriptTypeBiMap #86305
Workaround on GodotSharp duplicate key exception when adding generic entries to ScriptTypeBiMap #86305
Conversation
To confirm, you tested this PR and confirmed it with the changed code? This PR has not been merged yet so it hasn't solved anything yet |
I tested 83204 with the changed code and confirmed it does NOT solve the core issue. |
Is it possible for you to share a minimal reproduction for your case? |
I really would, however, it's not 100% reproductible and I am not sure what is the smoking gun in my case. If I had that, I could make a barebones project, but right now, all I could do is send my whole project. The only points I found that could've caused it to happen were:
In that case, if I build the code with it being dirty (not just building with no changes), there's a chance it breaks. It will break after a while of trying, but I can't figure what exactly causes it. |
The issue this PR is focusing on is related to the opening scene from my tests, that is, you need to have a specific scene opened while rebuilding your C# solution (to trigger the issue); hope this info will help you identify the issue in your project. It's okay for me if you send the whole project. |
From our usages, we can also found this issue 100% reproducible when generic entries being re-built in the editor. We believe that this PR has solved our problem in a patched version of GodotSharp. |
I'm wondering if it is a good thing to essentially silence the error while not solving the main issue (there are duplicate entries in the bimap / we are inserting generics in the bimap). Isn't it useful for us to have an error telling us there is an issue to fix? |
The issue we are discussing here is not user-related, it is an editor bug that requires fixing. The issue here is caused by GodotSharp creating duplicate generic entries out of nowhere (under certain circumstances, one user script that derives from a generic class can cause GodotSharp to generate duplicate System.Type instances) and causing trouble. The approach we took here is resolving the actual API that causing this issue, not silencing the error (what 83204 did). |
Yes, I know.
What I’m saying is: as discussed in the other linked PR, generics should not hit the bimap at all. IINW, what we do here is working around so that, when they do hit it, no duplicate key is raised. Essentially removing the errors, but leaving the generics in the map. Or am I misunderstanding the fix?
…>
|
@raulsntos Can you help me take a look? |
Previously, there was a bug that caused generics to hit the Bi-Map. |
My apologies, I misunderstood what the intent behind the patch was. You're right, this would prevent the insertion into the bimap in Though, I'm now a bit concerned (pardon me if this is annoying) by the fact |
That's a good point, I think I do need to talk to @Smallantsa for more detail. My testing (in SharpLab) indicates that this API does not work when passing How does it even work when returning null..... |
From the testing project I have here, when unloading assemblies, the |
It is basically when our script path is empty when iterating through the scripts to reload (here). I'm unsure of other possible cases where the path would be empty here (essentially: part of the class hierarchy for something, but no |
After discussion with @Delsin-Yu and @Smallantsa: It's ok to ignore ScriptPath for generic types. However, constructed generic types It's necessary to prevent re-instance cc @raulsntos |
Superseded by #87550 |
A workaround for #79519, this issue is a blocking issue for most .Net users.
Which is one of the causes of the Mega #78513
While #83204 resolved this issue by simply rejecting the duplicating addition, it still left the issue on the Native end and caused error message prints.We believe this PR(86305) solves the core issue of this whole chain.Found by @Smallantsa
Validated using This Repo
It turns out that this PR is yet another workaround on the issue, while it somehow resolves the symptoms, further investigation on
Generic Derivatives holding empty Script Path
is required to fully resolve this issue.By returning null on
ReflectionUtils.FindTypeInLoadedAssemblies
, this PR is a workaround for issues related to theSystem.ArgumentException: An item with the same key has already been added.
inScriptTypeBiMap
.While side effects are still to be validated.
It looks like the old way of obtaining a generic type will return a different instance for the type, resulting in a duplicate key exception inScriptTypeBiMap.Add(IntPtr scriptPtr, Type scriptType)
This new approach appears to return the same instance, so it should fix all issues related to: