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

Segfault on AI trying to build a valid tunnel #2875

Closed
DorpsGek opened this issue Apr 30, 2009 · 4 comments
Closed

Segfault on AI trying to build a valid tunnel #2875

DorpsGek opened this issue Apr 30, 2009 · 4 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)

Comments

@DorpsGek
Copy link
Member

divide opened the ticket and wrote:

Sometimes when AI is presumably trying to build a tunnel, OpenTTD segfaults with message:

openttd: /home/divide/projekty/openttd/src/ai/api/../../map_func.h:347: TileIndexDiff TileOffsByDiagDir(DiagDirection): Assertion `IsValidDiagDirection(dir)' failed.

I haven't got time to make an isolated testcase and haven't even pinpointed which AI is the culprit; I'm attaching a savegame (quite complex, alas, with several AIs and NewGRFs) that showcases the problem (just have it run for ca 2 minutes on fast forward). Having said that, attached patch fixes it and seems harmless otherwise.

Attachments

Reported version: trunk
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/2875
@DorpsGek
Copy link
Member Author

frosch wrote:

The issue is

::DoCommand(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL);

failing in AITunnel::GetOtherTunnelEnd.

The function should also work, when start/endtile cannot be bulldozed/excavated or the rail-/road-type is not available.


This comment was imported from FlySpray: https://bugs.openttd.org/task/2875#comment6003

@DorpsGek
Copy link
Member Author

DorpsGek commented May 1, 2009

divide wrote:

Actually it's failing in AITunnel::_BuildTunnelRoad1(). Here's the backtrace:

# 0 AITunnel::_BuildTunnelRoad1 () at /home/divide/projekty/openttd/src/ai/api/ai_tunnel.cpp:90
# 1 0x080eadce in AITunnel::BuildTunnel (vehicle_type=AIVehicle::VT_ROAD, start=37209)
at /home/divide/projekty/openttd/src/ai/api/ai_tunnel.cpp:80
# 2 0x080a3c96 in SQConvert::HelperT<bool ()(AIVehicle::VehicleType, unsigned int), false>::SQCall (instance=0x0,
func=0x80eac80 <AITunnel::BuildTunnel(AIVehicle::VehicleType, unsigned int)>, vm=0x879d540)
at /home/divide/projekty/openttd/src/ai/../script/squirrel_helper.hpp:275
# 3 0x080ae33e in SQConvert::DefSQStaticCallback<AITunnel, bool (
)(AIVehicle::VehicleType, unsigned int)> (vm=0x879d540)
at /home/divide/projekty/openttd/src/ai/../script/squirrel_helper.hpp:826
# 4 0x080751b1 in SQVM::CallNative (this=0x879d540, nclosure=0x8831198, nargs=3, stackbase=50, retval=@0xbff1ed2c, suspend=@0xbff1ed2b)
at /home/divide/projekty/openttd/src/3rdparty/squirrel/squirrel/sqvm.cpp:1133
# 5 0x08076f37 in SQVM::Execute (this=0x879d540, closure=@0x8437240, target=69, nargs=-1, stackbase=-1, outres=@0xbff1ee18, raiseerror=1,
et=ET_RESUME_OPENTTD) at /home/divide/projekty/openttd/src/3rdparty/squirrel/squirrel/sqvm.cpp:752
# 6 0x0804dd31 in sq_resumecatch (v=0x879d540, suspend=10000) at /home/divide/projekty/openttd/src/3rdparty/squirrel/squirrel/sqapi.cpp:1005
# 7 0x08246eb1 in Squirrel::Resume (this=0x861d0d8, suspend=10000) at /home/divide/projekty/openttd/src/script/squirrel.cpp:179
# 8 0x08089b34 in AIInstance::GameLoop (this=0x86e5098) at /home/divide/projekty/openttd/src/ai/ai_instance.cpp:322
# 9 0x08080d7f in AI::GameLoop () at /home/divide/projekty/openttd/src/ai/ai_core.cpp:69
# 10 0x081e43d4 in StateGameLoop () at /home/divide/projekty/openttd/src/openttd.cpp:1113
# 11 0x081e5707 in GameLoop () at /home/divide/projekty/openttd/src/openttd.cpp:1193
# 12 0x082cfd38 in VideoDriver_SDL::MainLoop (this=0x85c3968) at /home/divide/projekty/openttd/src/video/sdl_v.cpp:498
# 13 0x081e6279 in ttd_main (argc=2, argv=0xbff1f394) at /home/divide/projekty/openttd/src/openttd.cpp:692
# 14 0x082b9ad5 in main (argc=2, argv=0xbff1f394) at /home/divide/projekty/openttd/src/unix.cpp:251

GetOtherTunnelEnd is fine (otherwise my fix would've segfaulted too).


This comment was imported from FlySpray: https://bugs.openttd.org/task/2875#comment6004

@DorpsGek
Copy link
Member Author

DorpsGek commented May 1, 2009

divide wrote:

(I've just noticed that the backtrace is from just before the segfault. It happens on line 92, because of dir_1 being DIAGDIR_INVALID, because of end being TILE_INVALID.)


This comment was imported from FlySpray: https://bugs.openttd.org/task/2875#comment6005

@DorpsGek
Copy link
Member Author

DorpsGek commented May 6, 2009

Yexo closed the ticket.

Reason for closing: Fixed

In r16243.


This comment was imported from FlySpray: https://bugs.openttd.org/task/2875

@DorpsGek DorpsGek closed this as completed May 6, 2009
@DorpsGek DorpsGek added NewAI flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) labels Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)
Projects
None yet
Development

No branches or pull requests

1 participant