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

[GEN][ZH] Fix incorrect AsciiString hash implementation for non-stlport #450

Merged
merged 1 commit into from
Mar 29, 2025

Conversation

xezon
Copy link

@xezon xezon commented Mar 18, 2025

This error causes the game to crash early with non-stlport builds. The reason is that the hash impl for stlport does not work with the standard/new std::hash.

@xezon xezon added Bug Something is not working right Major Severity: Minor < Major < Critical < Blocker ZeroHour Relates to Zero Hour labels Mar 18, 2025
@DevGeniusCode
Copy link

DevGeniusCode commented Mar 23, 2025

Example error messages:

Sorry, a serious error occurred. (Error parsing INI
 file 'Data\INI\Object\chemicalgeneral.ini' (Line: 'ObjectReskin
 Chem_GLAHoleCommandCenter Chem_GLAHole ")
 )
ASSERTION FAILURE: Invalid FireSound MarauderTankWeapon
in Weapon 'MarauderTankGun'.

@xezon xezon changed the title Fix incorrect AsciiString hash implementation for non-stlport [ZH] Fix incorrect AsciiString hash implementation for non-stlport Mar 23, 2025
Comment on lines 193 to 202
size_t operator()(const AsciiString& ast) const
{
#ifdef USING_STLPORT
std::hash<const char *> tmp;
return tmp((const char *) ast.str());
#else
// TheSuperHackers @bugfix xezon 16/03/2024 std::hash implementation for STLPort does not work here.
// Use string view to capture c string and pass that to the hash function. No allocation.
std::hash<std::string_view> hasher;
return hasher(std::string_view(ast.str(), ast.getLength()));
#endif
Copy link

Choose a reason for hiding this comment

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

This change corrects the ASCII string parsing and fixes the behaviour.

std::string_view creates a C string out of the ascii string that the std::hash hasher can make use of.

@stevebone
Copy link

I have applied this change and the game launches without the ini parsing issues any longer as explained in #491. It crashes during the game but I am unsure whether that is related to this.

@Mauller
Copy link

Mauller commented Mar 24, 2025

I have applied this change and the game launches without the ini parsing issues any longer as explained in #491. It crashes during the game but I am unsure whether that is related to this.

You also have to apply the Asm fix in #479 as the original Asm causes runtime problems at random.

But this fix corrects the ini failures.

@xezon xezon force-pushed the xezon/fix-asciistring-hash branch from b23474e to 82200aa Compare March 26, 2025 20:33
@xezon
Copy link
Author

xezon commented Mar 26, 2025

Fix for Generals replicated. Comment simplified. To be merged after VS2022 CI.

@xezon xezon changed the title [ZH] Fix incorrect AsciiString hash implementation for non-stlport [GEN][ZH] Fix incorrect AsciiString hash implementation for non-stlport Mar 26, 2025
@DevGeniusCode DevGeniusCode added the Generals Related Generals only label Mar 26, 2025
@Mauller
Copy link

Mauller commented Mar 27, 2025

Shouldn't the Generals version also pass a cost reference? Matches the ZH version for completeness then.

@xezon
Copy link
Author

xezon commented Mar 27, 2025

Oh right. I did not copy that over properly.

@xezon xezon force-pushed the xezon/fix-asciistring-hash branch 2 times, most recently from 6ab582a to 54fa62d Compare March 27, 2025 20:26
@xezon
Copy link
Author

xezon commented Mar 27, 2025

Shouldn't the Generals version also pass a cost reference?

Fixed.

@xezon xezon force-pushed the xezon/fix-asciistring-hash branch from 54fa62d to a7670ae Compare March 29, 2025 10:57
@xezon xezon merged commit 1370428 into TheSuperHackers:main Mar 29, 2025
17 checks passed
@xezon xezon deleted the xezon/fix-asciistring-hash branch March 29, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working right Generals Related Generals only Major Severity: Minor < Major < Critical < Blocker ZeroHour Relates to Zero Hour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ZH] Build with VS 2022 unable to parse original INIs
5 participants