OpenTTD icon indicating copy to clipboard operation
OpenTTD copied to clipboard

[Bug]: CTD when all cargos are disabled by NewGRF, and cargo payment graph opened

Open 2TallTyler opened this issue 4 years ago • 5 comments

Version of OpenTTD

Master (7469f00)

Expected result

When all cargos are disabled by a NewGRF like Feature Disabler GRF, starting a new game without any cargos prompts the following error message on map generation:

No vehicles will be available at all Change your NewGRF configuration

I would expect opening the "Cargo payment rates" graph to show an empty graph with no cargos.

Actual result

Opening the "Cargo payment rates" graph causes a crash to desktop.

Steps to reproduce

  1. Enable the NewGRF Feature Disabler GRF with the parameter enabled to disable all cargos
  2. Start a game
  3. Open the "Cargo payment rates" graph
  4. CTD

2TallTyler avatar Sep 09 '21 11:09 2TallTyler

I would expect the game to abort world generation if there are no cargo types available. If there aren't any cargo types there isn't any game to play at all, since you have nothing to transport.

nielsmh avatar Sep 09 '21 13:09 nielsmh

It's perfect! You can build eye-candy objects all day without the distraction of pointless transportation! :p

ldpl avatar Sep 09 '21 13:09 ldpl

The game crashes in this case due to a division by 0 inside the following function: https://github.com/OpenTTD/OpenTTD/blob/41c40f130b907e73475f41706510a54a519b78e4/src/widget.cpp#L2172-L2180

I was able to reproduce the crash on master (2022-02-10) and in jgrpp (0.46.0). The stack trace of the latter crash was used to find the crashing function.

Crash files from the former crash: crash20220214021730.zip

James103 avatar Feb 14 '22 02:02 James103

I'm sure there's more places around the code that assumes that at least one cargo type is available too. That function is just the first that happens to be hit here.

nielsmh avatar Feb 14 '22 14:02 nielsmh

I think the proper fix is to abort map generation if no cargos are available, not to find and fix the crashes.

2TallTyler avatar Feb 14 '22 18:02 2TallTyler