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

Game crash from out-of-bounds helicopter, infinite circling with superfast aircraft #7619

Closed
James103 opened this issue Jun 6, 2019 · 7 comments · Fixed by #8531
Closed
Labels
bug Something isn't working
Milestone

Comments

@James103
Copy link
Contributor

James103 commented Jun 6, 2019

Version of OpenTTD

20190525-master-gef74af6766

Expected result

Game does not crash and both aircraft land properly.

Actual result

A. When you repeatedly start/stop any helicopter under certain conditions (such as below), the game can crash with Assertion failed at line 100 of d:\a\1\s\src\tile_map.h: tile < MapSize() due to an out-of-bounds position for that aircraft. This may be related to #272.
Crash files have been attached. Fixed by #7833.

B. When a regular aircraft (such as the Arwing) that is going very fast (>4000 km/h) tries to land in an airport, it circles around the destination airport infinitely. This has the following effects:

  • The aircraft can't be stopped as it is in flight.
  • The aircraft will continue to circle around the airport, but in a different way in that the circle is tighter/smaller and goes clockwise relative to the airport runway that it is tangent to.
  • The aircraft will be unable to escape that circling state, even when told to go to a different airport/hangar.
  • All of that means that the aircraft is effectively stuck there, unable to be removed.

Savegame attached for clarification.

Steps to reproduce

  1. Start new game (64x4096) with OpenGFX Airports v0.5.0 (disable "Airport noise limits") and Kasskroket's Fictional Aircraft v1.0.2 (disable "Limit Arwing top speed").
  2. Build Intercontinental airport at top of the map (1,1).
  3. Build airport at bottom of the map (1,4095). Save the game.
  4. Purchase any helicopter at the top airport and add the top airport to its orders.
  5. Start the helicopter.
  6. After some time, repeatedly start/stop the helicopter while fastforwarding.
  7. After a while, the game will crash with Assertion failed at line 100 of d:\a\1\s\src\tile_map.h: tile < MapSize() because it accesses an out-of-bounds/invalid tile from the map array.
  8. Reload the save you made in step 3.
  9. Purchase "Arwing" aircraft and add both airports to its orders.
  10. Start the aircraft.
  11. When the aircraft gets to the destination, it will circle around indefinitely.
@James103 James103 changed the title Game crash from superfast helicopter, infinite circling with superfast aircraft Game crash from out-of-bounds helicopter, infinite circling with superfast aircraft Jun 7, 2019
@Ben79487
Copy link

I don't think this scenario is likely to occur in a game...

@LordAro
Copy link
Member

LordAro commented Nov 2, 2019

This should really be separate issues, but whatever

First issue is crashing the game due to trying to render the error message ("aircraft cannot be stopped") at an invalid tile:

#0  0x00007ffce83da839 in RaiseException () from C:\WINDOWS\System32\KernelBase.dll
#1  0x00007ffcea39ae7b in raise () from C:\WINDOWS\System32\msvcrt.dll
#2  0x00007ffcea39dab9 in msvcrt!_wassert () from C:\WINDOWS\System32\msvcrt.dll
#3  0x00000000004d34c2 in GetTileType (tile=tile@entry=268436981) at C:/msys64/home/LordAro/OpenTTD/src/tile_map.h:101
#4  0x00000000004d551d in GetSlopePixelZ (x=3920, y=16777296) at C:/msys64/home/LordAro/OpenTTD/src/landscape.cpp:348
#5  0x0000000000481823 in RemapCoords2 (x=3920, y=16777296) at C:/msys64/home/LordAro/OpenTTD/src/landscape.h:102
#6  0x0000000000724833 in ErrmsgWindow::OnInitialPosition (this=0x315179b0, sm_width=<optimized out>, sm_height=<optimized out>,
    window_number=<optimized out>) at C:/msys64/home/LordAro/OpenTTD/src/error_gui.cpp:229
#7  0x00000000006a089a in Window::FinishInitNested (this=0x315179b0, window_number=0)
    at C:/msys64/home/LordAro/OpenTTD/src/window.cpp:1832
#8  0x00000000006a0928 in Window::InitNested (this=<optimized out>, window_number=<optimized out>)
    at C:/msys64/home/LordAro/OpenTTD/src/window.cpp:1844
#9  0x00000000007249b0 in ErrmsgWindow::ErrmsgWindow (this=0x315179b0, data=...)
    at C:/msys64/home/LordAro/OpenTTD/src/error_gui.cpp:184
#10 0x0000000000482258 in ShowErrorMessage (summary_msg=<optimized out>, detailed_msg=65535, wl=wl@entry=WL_INFO, x=x@entry=3920,
    y=y@entry=16777296, textref_stack_grffile=textref_stack_grffile@entry=0x0, textref_stack_size=0,
    textref_stack=0xbdf3c0 <CommandCost::textref_stack>) at C:/msys64/home/LordAro/OpenTTD/src/error_gui.cpp:425
#11 0x000000000045ea22 in DoCommandP (tile=268436981, p1=13, p2=0, cmd=245301353, callback=0x0, text=0x0, my_cmd=true)
    at C:/msys64/home/LordAro/OpenTTD/src/command.cpp:587
#12 0x000000000067a29c in StartStopVehicle (v=0x31319810, texteffect=<optimized out>)
    at C:/msys64/home/LordAro/OpenTTD/src/vehicle_gui.cpp:2400
...

Note the y value of 16777296 for ShowErrorMessage. This is due to the vehicle's tile being invalid and outside of the range of the map, caused by the intercontinental airport's holding pattern being as wide as it is. I don't think it's distinct to helicopters, but I've been unable to reproduce with standard aircraft. Something to do with the circling pattern, perhaps?

Not sure whether the best course of action to fix that would be - it's not enough just to add some clamps to ShowErrorMessage, as the vehicle's position is invalid - it will just cause other issues later on (e.g. when saving). Could perhaps adjust the intercontinental airport's holding pattern?

The other issue is similarly niche. It only seems to happen when the aircraft approaches from certain directions - from the north east doesn't seem to trigger it, but from the south west (and presumably north west as per original report) does. Adding some print statements in indicates that the aircraft is stuck in movement data index "19" (for city airport) and just never leaves it. Presumably it's just going fast enough to go "past" the end of the pattern and being forced to begin it again? This requires further debugging though

JGRennison added a commit to JGRennison/OpenTTD-patches that referenced this issue Nov 7, 2019
JGRennison added a commit to JGRennison/OpenTTD-patches that referenced this issue Nov 13, 2019
JGRennison added a commit to JGRennison/Upstream-OpenTTD that referenced this issue Nov 13, 2019
This fixes part A of OpenTTD#7619, but not part B.

Vehicle::x_pos and Vehicle::y_pos are not required to be within the map bounds.

See also: GetTileHeightBelowAircraft()
nielsmh pushed a commit that referenced this issue Nov 14, 2019
This fixes part A of #7619, but not part B.

Vehicle::x_pos and Vehicle::y_pos are not required to be within the map bounds.

See also: GetTileHeightBelowAircraft()
douiwby pushed a commit to douiwby/OpenTTD that referenced this issue Apr 16, 2020
This fixes part A of OpenTTD#7619, but not part B.

Vehicle::x_pos and Vehicle::y_pos are not required to be within the map bounds.

See also: GetTileHeightBelowAircraft()
@TrueBrain TrueBrain added the bug Something isn't working label Jan 3, 2021
@TrueBrain TrueBrain added this to the 1.11.0 milestone Jan 5, 2021
@TrueBrain
Copy link
Member

TrueBrain commented Jan 8, 2021

@James103 Can you re-test B) if you have the time? As the savegame you supplied works fine for me on latest master (and nightly by extend). Possibly this got fixed over the last few months somewhere by accident :) Tnx!

Edit: nevermind, took me a bit of trying, but I got it. It looks AMAZING :D

@TrueBrain
Copy link
Member

TrueBrain commented Jan 8, 2021

2021-01-08.20-37-27.mp4

I am very tempted to leave in this bug. It just looks so perfect. This is not speed up and fast-forward is NOT on.

@James103
Copy link
Contributor Author

James103 commented Jan 8, 2021

I got the same behavior with a similar setup.

@TrueBrain
Copy link
Member

It seems the airport in question has no holding pattern. Not a NewGRF expert, so I cannot confirm really, but I can see that with the savegame and that airport, the plane never reaches a hold state :)

@TrueBrain
Copy link
Member

Okay, so basically: plane is going to a magic tile that is the entry of the airport. But it is going so quickly, it overshoots it COMPLETELY, turns around to correct for it, and by the magic of the circling being an exact multiplication of the airplane speed, it keeps overshooting it with the same amount, making the same circle, etc etc etc.

Basically: plane too fast :D We should be able to solve this ...

TrueBrain added a commit to TrueBrain/OpenTTD that referenced this issue Jan 8, 2021
For non-NewGRF planes, "count" is never above 1. So planes can
smoothly be guided to their destination. For NewGRF planes, they
can go as quick as "count" values of 20. This easily overshoots
the target. So, calculate if the plane will overshoot, and start
nudging him to the destination earlier. You won't notice this
either way, as it all happens within a single tick.
TrueBrain added a commit that referenced this issue Jan 11, 2021
For non-NewGRF planes, "count" is never above 1. So planes can
smoothly be guided to their destination. For NewGRF planes, they
can go as quick as "count" values of 20. This easily overshoots
the target. So, calculate if the plane will overshoot, and start
nudging him to the destination earlier. You won't notice this
either way, as it all happens within a single tick.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants