-
Notifications
You must be signed in to change notification settings - Fork 97
Fix Tracker.AddTypeToTracker #1024
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
Conversation
|
here i make
|
|
Can you name a specific case of this? |
|
https://github.com/LozenChen/TAS-Helper/blob/598d77dd7bfda322fb7cd1ffebcb9b8c10f860ee/Source/Gameplay/AutoWatchEntity/CoreLogic.cs#L24 https://github.com/DemoJameson/Celeste.SpeedrunTool/blob/6b8499e9793ce6c0cba984376c5849000982eb27/SpeedrunTool/Source/TeleportRoom/TeleportRoomUtils.cs#L502-L503 i know |
|
I just wrote a simple mod to show what happens Most codes lie in https://github.com/LozenChen/LozenTestMod/blob/master/Source/Test/BugReproduce.cs Normally
However if we
|
| // Make sure the tracker knows about both the type and trackedAs type, to fix scenarios like `[TrackedAs(typeof(UntrackedType))]` | ||
| bool updated = false; | ||
| if (knownTypes is not null) { | ||
| updated = knownTypes.Add(type); | ||
| updated |= knownTypes.Add(trackedAsType); | ||
| } | ||
| // check IsAbstract later, make AddTypeToTracker(type: typeof(Celeste.CutsceneEntity), trackedAs: null, inheritAll: true) work properly | ||
| if (type.IsAbstract) { | ||
| return false; | ||
| return updated; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Make sure the tracker knows about both the type and trackedAs type, to fix scenarios like `[TrackedAs(typeof(UntrackedType))]` | |
| bool updated = false; | |
| if (knownTypes is not null) { | |
| updated = knownTypes.Add(type); | |
| updated |= knownTypes.Add(trackedAsType); | |
| } | |
| // check IsAbstract later, make AddTypeToTracker(type: typeof(Celeste.CutsceneEntity), trackedAs: null, inheritAll: true) work properly | |
| if (type.IsAbstract) { | |
| return false; | |
| return updated; | |
| } | |
| // Make sure the tracker knows about trackedAs type, to fix scenarios like `[TrackedAs(typeof(UntrackedType))] | |
| // Vanilla adds the target type (`trackedAsType`) regardless of whether it's abstract or not | |
| bool updated = knownTypes.Add(trackedAsType); | |
| if (type.IsAbstract) { | |
| return updated; | |
| } |
Why not just get rid of the knownTypes.Add(type)? As far as my understanding goes when a type T is in knownTypes it means that the tracker is aware of it (not just that it is on the keys of tracked) and T is tracked, tracker.GetEntities<T>() will return instances of T. (In other words: tracked[typeof(T)].Contains(typeof(T)) is true for T when T is in knownTypes.)
Furthermore, trackedAsType should always be added to knownTypes since it will be present on some list in the values (not keys) of tracked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I reviewed the commit history again, and it looks like we were very close to a correct solution earlier
Wartori54
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, the only edge case im currently worried about is in the case where a mod uses TrackedAs and relies on GetEntities not throwing when used on the type that had the TrackedAs applied to:
[TrackedAs(typeof(A)]
public class E : Entity { ... }
public class A : Entity { ... }
// Somewhere else
tracker.GetEntities<E>(); // This will throw now, instead of returning an empty list if `E` was also not `Tracked` manually| return false; | ||
| } | ||
|
|
||
| // Make sure the tracker knows about both the type and trackedAs type, to fix scenarios like `[TrackedAs(typeof(UntrackedType))]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave the comment, since it is still relevant, but move it to the right place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a mod uses TrackedAs and then tries GetEntities<OriginalClass>, that's already incorrect usage. I think we should just let it crash here rather than hide the bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I'm mostly worried about backwards compat.
JaThePlayer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct, let's hope no mod did anything stupid (like that TrackedAs(UntrackedType) scenario from earlier)
|
The pull request was approved and entered the 3-day last-call window. |
|
The last-call window for this pull request ended. It can now be merged if no blockers were brought up. |
This fixes #1020