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 #9546: Crash when no industries are present in game #9726

Merged
merged 1 commit into from Apr 30, 2022

Conversation

Kiptoke
Copy link
Contributor

@Kiptoke Kiptoke commented Dec 2, 2021

Motivation / Problem

Resolves #9546:
When industries are removed entirely using the feature disabler NewGRF, a crash occurs when the player opens up the "Fund New Industries" window.

Description

In the GetIndustrySpec function within industry_cmp.cpp, changed the assertion statement from assert(thistype < NUM_INDUSTRYTYPES); to assert(thistype <= NUM_INDUSTRYTYPES);

This resolves #9546 - now instead of the Fund New Industries window crashing the game, it shows up empty.

Limitations

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 touches english.txt or translations? Check the guidelines
  • 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')

src/industry_cmd.cpp Outdated Show resolved Hide resolved
src/industry_gui.cpp Outdated Show resolved Hide resolved
@Kiptoke Kiptoke requested a review from nielsmh December 9, 2021 02:17
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

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

You seem to have changed file modes to 100644 -> 100755 as well - please revert this change

(If you're on Windows, this can be tricky - see http://blog.lesc.se/2011/11/how-to-change-file-premissions-in-git.html (but use -x instead of +x )

const IndustrySpec *indsp = GetIndustrySpec(this->index[this->selected_index]);
SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
} else {
SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && false) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY);
Copy link
Member

Choose a reason for hiding this comment

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

&& false ?

I think we can remove some code here

rubidium42
rubidium42 previously approved these changes Feb 4, 2022
@LordAro LordAro changed the title Fix: Prevents crash when no industries are present Fix #9546: Crash when no industries are present in game Apr 30, 2022
@rubidium42 rubidium42 merged commit 5ea55f3 into OpenTTD:master Apr 30, 2022
@Kiptoke Kiptoke deleted the no_industry_fund branch May 5, 2022 22:28
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.

[Crash]: Assertion failed on "Fund new industry" when no industries exist
5 participants