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

Fix #8276: Crash when a NewGRF object's size was not set #8719

Merged
merged 1 commit into from Feb 21, 2021

Conversation

@LordAro
Copy link
Member

@LordAro LordAro commented Feb 21, 2021

Motivation / Problem

#8276
NewGRF's object size defaulted to 0x0, which if the object's size property (0xBC) was not set, and the game falls on its face trying to render a 0x0 object.

Description

Add a default of 1x1, and add validation that the GRF setting a size does not set a 0 width or height

Limitations

Technically speaking, the actual bug is that the size (0xBC) wasn't set in the GRF at all. We still can't detect that, and I don't see a way to do so with the current code layout.

Probably an NML bug that it allows this at all.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')
@LordAro LordAro requested a review from frosch123 Feb 21, 2021
glx22
glx22 approved these changes Feb 21, 2021
Copy link
Contributor

@glx22 glx22 left a comment

Seems correct, and yes probably an NML bug.

@LordAro LordAro merged commit 8157af6 into OpenTTD:master Feb 21, 2021
10 checks passed
@LordAro LordAro deleted the bug8276 branch Feb 21, 2021
@glx22
Copy link
Contributor

@glx22 glx22 commented Aug 31, 2021

And now I did some digging in ttdpatch source, and it seems an object is just not available if size < 0x11, same if no name is set, or of course no climate is set. They even mention it here. Of course it's nowhere in the specs.

So adding more checks to

bool ObjectSpec::IsEverAvailable() const
{
return this->enabled && HasBit(this->climate, _settings_game.game_creation.landscape) &&
(this->flags & ((_game_mode != GM_EDITOR && !_generating_world) ? OBJECT_FLAG_ONLY_IN_SCENEDIT : OBJECT_FLAG_ONLY_IN_GAME)) == 0;
}
might be a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants