Skip to content

Conversation

@Mauller
Copy link

@Mauller Mauller commented Jul 25, 2025

This PR fixes a game crash caused when a unit is created with veterancy and the object has an upgrade unlocked that attempts to apply a terrain decal. This can be reproduced with the chemical suits upgrade of the USA and is likely the reason why the chemical suit upgrade is disabled on USA pilots.

When an object is created the thing factory runs through all of it's behaviour modules and calls their onCreate() function if there is one available.

Units created with veterancy have the veterancyGainCreate module applied to them. This module iterates over all of the objects behaviour modules and forces them to update their status.

If the chemical suits upgrade or any other upgrade that applies a terrain decal is unlocked then it will crash the game. This is due to the objects drawable not being applied yet.

Normally the object will get its drawble created and bound to it after the behaviour modules have been iterated over. But to get around the veterancyGainCreate issue, we call the sendObjectCreated() at the end of the objects constructor.
originally it would be called within initObject that gets called after the behaviour modules onCreate loop within ThingFactory::newObject.

This then allows modules that would update the drawable to do so without crashing the game.

This is also fully retail compatible due to the ordering being maintained in the original initialisation sequence beyond creating the drawable and applying it to the object.

@Mauller Mauller self-assigned this Jul 25, 2025
@Mauller Mauller added Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Crash This is a crash, very bad labels Jul 25, 2025
@Mauller Mauller added this to the Major bug fixes milestone Jul 25, 2025
@Mauller Mauller force-pushed the fix-vet-create-crashes branch from d41c7e4 to b2cf90c Compare July 25, 2025 15:00
@Mauller Mauller force-pushed the fix-vet-create-crashes branch from b2cf90c to c4331d1 Compare July 26, 2025 14:15
@Mauller
Copy link
Author

Mauller commented Jul 26, 2025

Updated now.

Copy link

Choose a reason for hiding this comment

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

How about we rename GameLogic::sendObjectCreated to GameLogic::sendObjectInitialized, which modifies the object and drawable states. Called from Object::initObject.

And then we create a new GameLogic::sendObjectCreated that allocates the drawable and binds object and drawable together. Called from Object::Object.

And GameLogic::sendObjectDestroyed stays as is. Called from Object::~Object.

That would be logically cleaner and fit more into the original code design.

Unless there is a reason why we cannot create a drawable inside constructor of Object. But that looks to be ok.

Copy link
Author

@Mauller Mauller Jul 29, 2025

Choose a reason for hiding this comment

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

if anything, the drawable could be set within GameLogic::friend_createObject it can't be done within the objects constructor since it won't have the template data at that point to set the relevant drawable information.

The object and drawable binding also can't happen too soon otherwise it changes the order of execution of some other operations and can cause it to mismatch with retail.

Which was why i just create and set the drawable early but don't fully bind or initialise it till it would happen within the original code.

Copy link
Author

Choose a reason for hiding this comment

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

Just looking at this more, the thingFactory is managing the creation of the object and drawable. Using templated data to initialise them to the correct object / drawable.

I don't think it is necessarily going to be any cleaner to do it from within Object::Object since the thing factory still needs to get called and needs to be known about by an object then.

Copy link

Choose a reason for hiding this comment

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

Please check if this change works as a fix:
xezon@f563b0e

I tested this against the Golden Replay and it passed.

It also looks as if it should prevent the crash and it would be the cleanest solution I can think of.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah this tweak appears to help resolve the issue without mismatching.

Originally i tried moving the call to obj->initObject(); within ThingFactory::newObject to be before the behaviour module onCreate() loop, but that caused mismatching. So considered that anything within it might casue a mismatch if performed too soon.

Will update the PR and push the changes with the extra context comments in a sec.

@Mauller Mauller force-pushed the fix-vet-create-crashes branch from c4331d1 to 934f5de Compare August 1, 2025 13:42
@Mauller
Copy link
Author

Mauller commented Aug 1, 2025

quick rebase before making tweaks

@Mauller Mauller force-pushed the fix-vet-create-crashes branch from 934f5de to 6c610ee Compare August 2, 2025 09:31
@Mauller
Copy link
Author

Mauller commented Aug 2, 2025

Tweaked with recommendations and tested against multiple replays.

I created a replay with the fix and created troops with chemical suits, then ran it back in a build without the fix and it did not mismatch.

@Mauller Mauller changed the title [GEN][ZH] Fix veterancyGainCreate() crash when an object is created with an upgrade that applies a terrain decal bugfix(crash): Fix veterancyGainCreate() crash when an object is created with an upgrade that applies a terrain decal Aug 2, 2025
@Mauller Mauller force-pushed the fix-vet-create-crashes branch from 6c610ee to efceddc Compare August 2, 2025 11:10
@Mauller
Copy link
Author

Mauller commented Aug 2, 2025

Tweaked based on feedback, should be good now

@Mauller Mauller force-pushed the fix-vet-create-crashes branch from efceddc to b38d423 Compare August 2, 2025 11:11
@Mauller
Copy link
Author

Mauller commented Aug 2, 2025

Ditto

@xezon xezon changed the title bugfix(crash): Fix veterancyGainCreate() crash when an object is created with an upgrade that applies a terrain decal bugfix(crash): Fix crash when an object is created with an upgrade that applies a terrain decal Aug 2, 2025
@xezon
Copy link

xezon commented Aug 2, 2025

Is the Description of this Pull up-to-date?

@xezon xezon modified the milestones: Major bug fixes, Stability fixes Aug 2, 2025
@Mauller Mauller force-pushed the fix-vet-create-crashes branch from b38d423 to 858ad72 Compare August 2, 2025 11:55
@Mauller
Copy link
Author

Mauller commented Aug 2, 2025

Is the Description of this Pull up-to-date?

Yes i already tweaked it.

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Looks good.

@xezon xezon changed the title bugfix(crash): Fix crash when an object is created with an upgrade that applies a terrain decal bugfix(crash): Fix crash when an object is created with veterancy and an upgrade that applies a terrain decal Aug 3, 2025
@xezon xezon changed the title bugfix(crash): Fix crash when an object is created with veterancy and an upgrade that applies a terrain decal bugfix(object): Fix crash when an object is created with veterancy and an upgrade that applies a terrain decal Aug 3, 2025
@xezon xezon added the Mod Relates to Mods or modding label Aug 3, 2025
@xezon xezon merged commit 3a58ec4 into TheSuperHackers:main Aug 3, 2025
17 checks passed
@xezon xezon deleted the fix-vet-create-crashes branch August 3, 2025 08:41
fbraz3 pushed a commit to fbraz3/GeneralsX that referenced this pull request Nov 10, 2025
…d an upgrade that applies a terrain decal (TheSuperHackers#1359)

Most notably happens when spawning the USA Pilot with the Chemical Suits upgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Crash This is a crash, very bad Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker Mod Relates to Mods or modding ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Game Crash in void Drawable::setTerrainDecal - Chemical suit + Instant build infantry - Mod Map

2 participants