-
-
Notifications
You must be signed in to change notification settings - Fork 875
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
Game crashes trying to sell huge wagon chain #8295
Comments
Please attach the generated crash log to the issue too. |
@nielsmh Where is this log located on Windows? |
By default, in your Documents\OpenTTD\ folder. The path is usually shown in the crash dialog. If you get something other than OpenTTD's own crash dialog up, then please screenshot or more detailed describe the crash. |
@nielsmh There is no dialog and no log in the folder you mentioned. The game hangs for a second, and then closes. No dialogs, no errors, nothing. |
Okay I reproduce it with that save. It seems to hit 100% CPU use (on a single core) and allocate a bunch more memory while it's doing that whatever. |
This appears to be caused by an AI. When I collect a memory dump while it's frozen, I get a state where player 3 (RailwAI v25) is selling a rail wagon. I'm not sure why it hangs doing that, but two separate dumps taken at random times during the freeze points to the same place in the code with near-identical stacks. Around here is where it is in my two dumps, but this may not be the direct cause in itself. |
Interestingly the depot at 130x784 (Bundtown, by train 8) has a free wagon chain of what appears to be 27,126 wagons. |
Interesting. In attempt to salvage the save game, I tried to delete 3rd AI via |
Apparently the 3rd AI player has bought an ungodly amount of wagons and then trying to sell them all at once, causing the crash. |
The game stack overflows upon loading the attached save and doing any of the following (all lead to similar crash reports):
A possible fix would be to optimize functions that handle wagon chains, preferably removing recursion from the process. If that isn't feasible, a workaround would be to just limit the length of wagon chains to a reasonable number, for example 256 or 1,024 wagons in a single chain. |
I managed to salvage the save on Linux. I loaded save with the game version for Debian 10 x64, and then used |
On the In this case you would still run out of stack even if that was removed. (Maintaining pre-filtered lists of vehicles by type/etc for faster iteration does have non-trivial performance benefits, and is useful in other areas. Using different pools would require a rethink of ID allocation and the savegame format.) |
Wonder if we could do that, but without special-casing disaster vehicles and adding more global variables. An extension to pool (iterators), perhaps? |
I would actually pose that this is a case of premature generalisation. The only implemented disaster vehicle that targets any vehicles at all targets front road vehicles. Which makes checking for this on deleting a Train vehicle quite pointless. |
Possible side-track, I'm not clear what |
PreDestructor is a method of Vehicle, but it does various things which require that the the members and virtual methods of its derived classes are still alive. In the case of Train, after ~Train returns all of Trains members are destructed and the vtable reassigned before ~Vehicle is called. |
We added code that prevents this situation from happening. Although we can make some performance enhancements to make removing such long chains quicker, the real problem of course that the AI managed to create such a long vehicle chain. This is not okay, and shouldn't happen :P So at least that is solved now :D @LordAro : do you want to solve that the game doesn't close itself when deleting such huge chains? Or do you consider this mitigation sufficient to close the issue? |
I vote that #8533 is sufficient mitigation and we can knock this off the issue tracker. 🙂 If anyone disagrees, feel free to reopen (or maybe open a more specific issue about how to best handle disaster vehicles in destructors). |
Version of OpenTTD
1.10.3 Windows 10 64-bit
Expected result
The game does not crash.
Actual result
The game crashes after roughly two months in-game. The exact date does not matter - you can wait for a monthly autosave, load it, and the game will crash in two months.
Steps to reproduce
Granted I have NewGRFs installed, but the game shouldn't crash like that. In debug mode, there is no relevant errors prior to crash.
Savegame
The text was updated successfully, but these errors were encountered: