Skip to content

Conversation

@fabiangreffrath
Copy link
Member

Fixes #1756

Copy link
Member

@turol turol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments would be nice to explain why we are checking this.

Isn't the check in S_StartSoundAtVolume the wrong way? When called from problematic EV_RotatePoly it's likely that the bogus check for origin>player evaluates to true so the line should be

if (origin->thinker.function == P_DegenMobjThinker || origin->player)

@turol
Copy link
Member

turol commented Sep 14, 2025

I remembered that identical code folding optimization can lead to a situation where two functions have the same address and the comparison breaks. This code might be fragile.

@fabiangreffrath
Copy link
Member Author

Isn't the check in S_StartSoundAtVolume the wrong way? When called from problematic EV_RotatePoly it's likely that the bogus check for origin>player evaluates to true so the line should be

Yes, you are right, thank you! I even said this myself here: #1756 (comment)

I have inverted the logic and added a comment.

@fabiangreffrath
Copy link
Member Author

I remembered that identical code folding optimization can lead to a situation where two functions have the same address and the comparison breaks. This code might be fragile.

Eh, could you elaborate, please? What you describe here sounds more like a compiler bug to me.

@turol
Copy link
Member

turol commented Sep 14, 2025

Eh, could you elaborate, please? What you describe here sounds more like a compiler bug to me.

It's a space optimization by the compiler and/or linker. GNU gold at least implements it and MSVC has some version of it as "identical COMDAT folding". Most of the time it doesn't matter if functions have identical addresses or not and it can save significant amounts of space. At least gold is supposed to have a safe mode which will avoid merging functions which have their addresses taken but it might require support from the compiler. It has also been known to break things in the past but those are classified as bugs.

To be safe you could add something unique to P_DegenMobjThinker. A log message or an error call if you're sure it will never actually get called. That should inhibit the optimization and prevent any bugs.

@fabiangreffrath
Copy link
Member Author

I see, that's a valid point, thank you. I didn't even know this could cause an issue.

@fabiangreffrath fabiangreffrath merged commit 7172d2b into master Sep 16, 2025
6 checks passed
@fabiangreffrath fabiangreffrath deleted the P_DegenMobjThinker branch September 16, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hexen sound sequences inconsistent between architectures

3 participants