-
Notifications
You must be signed in to change notification settings - Fork 271
bugfix(object): Clean up stranded occupants and preserve teardown lookup #3308
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
base: main
Are you sure you want to change the base?
Changes from all commits
a4f6a80
c0efa7a
a25c611
59f318f
d3c76f9
c7c29a6
555259a
6fd4b0a
8f37699
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,9 @@ | |
| #include "Common/Team.h" | ||
| #include "Common/ThingFactory.h" | ||
| #include "Common/ThingTemplate.h" | ||
| #if RTS_GENERALS && RETAIL_COMPATIBLE_CRC | ||
| #include "Common/TunnelTracker.h" | ||
| #endif | ||
| #include "Common/Upgrade.h" | ||
| #include "Common/WellKnownKeys.h" | ||
| #include "Common/Xfer.h" | ||
|
|
@@ -636,6 +639,23 @@ void Object::onRemovedFrom( Object *removedFrom ) | |
| m_containedByFrame = 0; | ||
| } | ||
|
|
||
| #if RTS_GENERALS && RETAIL_COMPATIBLE_CRC | ||
| //------------------------------------------------------------------------------------------------- | ||
| void Object::removeFromTunnelContain() | ||
| { | ||
| for (Int i = 0; i < ThePlayerList->getPlayerCount(); ++i) | ||
| { | ||
| TunnelTracker* tracker = ThePlayerList->getNthPlayer(i)->getTunnelSystem(); | ||
| if (tracker && tracker->removeFromContain(this)) | ||
| { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| onRemovedFrom(nullptr); | ||
| } | ||
| #endif | ||
|
|
||
| //------------------------------------------------------------------------------------------------- | ||
| //------------------------------------------------------------------------------------------------- | ||
| Int Object::getTransportSlotCount() const | ||
|
|
@@ -695,7 +715,21 @@ void Object::onDestroy() | |
| // This is the old cleanUpContain safeguard. Say goodbye so they don't try to look us up. | ||
| if( m_containedBy && m_containedBy->getContain() ) | ||
| { | ||
| m_containedBy->getContain()->removeFromContain( this ); | ||
| #if RTS_GENERALS && RETAIL_COMPATIBLE_CRC | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am skeptical about this change because it explicitly addresses Generals, indicating that this is no issue in Zero Hour, which then begs the question why and can we merge the Zero Hour code responsible for fixing this instead of having a separate fix for Generals that eventually will conflict with Zero Hour when merging? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will all the code of this change disappear on merge? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only if the merge coincides with abandoning retail compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok can you review this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xezon The Generals specific changes / additions need to be replicated to Zero Hour, right? (behind There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think he just applied that.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is mirrored into Zero Hour behind the same macro. |
||
| // TheSuperHackers @bugfix bobtista / Caball009 17/09/2026 Remove stranded tunnel occupants during destruction. | ||
| // Surrendering can transfer a tunnel without updating its tunnel tracker. If that tunnel is destroyed, | ||
| // m_containedBy still points to the freed tunnel, and its ID is read here through that stale pointer. | ||
| // An unregistered ID means the tunnel is gone, so this object is removed from the tunnel trackers directly. | ||
| // This is a limited workaround that keeps retail compatibility. It cannot detect reuse of the freed memory. | ||
| if (!TheGameLogic->findObjectByID(m_containedBy->getID())) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it still reads through the stale pointer and cannot detect memory reused by another live object. Those limitations are in the description. The underlying dangling-pointer issue remains in #3316. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. The PR description explicitly documents both limitations, and #3316 tracks the broader dangling- |
||
| { | ||
| removeFromTunnelContain(); | ||
| } | ||
| else | ||
| #endif | ||
| { | ||
| m_containedBy->getContain()->removeFromContain(this); | ||
| } | ||
| } | ||
|
|
||
| // | ||
|
|
||
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.
Minor: Maybe this should be protected like all the other ones above?
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.
Done