The International Simutrans Forum

 

Author Topic: [BUG] bridgeheads can start in illegal locations  (Read 671 times)

0 Members and 1 Guest are viewing this topic.

Offline Freahk

  • Devotee
  • *
  • Posts: 1336
  • Languages: DE, EN
[BUG] bridgeheads can start in illegal locations
« on: July 28, 2020, 01:11:16 PM »
What happened?
On Bridgewater, a town forcefully built a bridge in a very strange way, causing a jam on Freddys railway line.

It is generally possible to force-build (ctrl-drag) a bridge to end on a through way.
This in independant of the involved waytype as long as both involved types are either the same or there is a level crossing defined in between those types.
Such bridges do not only look ugly, but those will also cut the route of the trough way, as just happened on bridgewater.

Another issue with this, I was not able to reproduce is a crash that can be caused by the construction of such bridges.
While building the crash setup, the game crashed twice, but I was not able to see the exact error message (the window closes immediately after showing it) nor was i able to get this reproduced.
I wll add instructions once I am able to reproduce the crash.

How to reproduce?
See the attached save, I have built any combination I could think of.
You can build any of these by
1. building the way on the ground
2. ctrl-dragging a bridge from a spare tile straight onto a flat way on the ground.

Thanks to Freddy, who noticed this behavior was not specific to towns constructing roads, but general to road construction. This made it much easier to provide a reproduction case.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20274
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #1 on: July 29, 2020, 01:10:56 PM »
Thank you for the report. The bridge building code is largely unchanged from Standard - does anyone know whether this issue is unique to Extended or whether it can be reproduced in Standard?

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: [BUG] bridgeheads can start in illegal locations
« Reply #2 on: July 29, 2020, 01:39:43 PM »
Thank you for the report. The bridge building code is largely unchanged from Standard - does anyone know whether this issue is unique to Extended or whether it can be reproduced in Standard?
I can't seem to reproduce this in Standard

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20274
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #3 on: July 29, 2020, 01:43:22 PM »
I can't seem to reproduce this in Standard

Thank you for confirming.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20274
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #4 on: July 29, 2020, 06:08:19 PM »
I believe that I have now fixed this: this was very complex, and appears to arise in code from Standard: I was unable to find any divergence from Standard in the code in which this occurs.

Standard may well also suffer a crash, which I also fixed, when a three tile bridge was built with its far end immediately adjacent to a perpendicular way for which no crossing with the bridge's way was defined in the pakset.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: [BUG] bridgeheads can start in illegal locations
« Reply #5 on: July 29, 2020, 08:06:45 PM »
Have had a quick look at the fixes and I would be a bit wary of these - it seems like they might point to an underlying issue in the code elsewhere that differs from Standard and this could be leading to as yet unnoticed errors elsewhere in Extended. I'm suspecting that because Standard (and Extended) have managed so long without the checks in a section of code that goes back probably a decade. Also keeping code like this the same helps in keeping the versions as in sync with each other as possible.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20274
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #6 on: July 29, 2020, 08:20:16 PM »
Have had a quick look at the fixes and I would be a bit wary of these - it seems like they might point to an underlying issue in the code elsewhere that differs from Standard and this could be leading to as yet unnoticed errors elsewhere in Extended. I'm suspecting that because Standard (and Extended) have managed so long without the checks in a section of code that goes back probably a decade. Also keeping code like this the same helps in keeping the versions as in sync with each other as possible.

I am afraid that I am at a loss as to what the relevant difference between the codebases is here; you may also want to check the specific case to which I refer above to see whether this does provoke a crash in Standard.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: [BUG] bridgeheads can start in illegal locations
« Reply #7 on: July 29, 2020, 08:37:56 PM »
I am afraid that I am at a loss as to what the relevant difference between the codebases is here; you may also want to check the specific case to which I refer above to see whether this does provoke a crash in Standard.
I have without success in creating a crash in Standard unfortunately (or possibly fortunately)! Have tried to trace it a little in Extended but likewise can’t see the obvious cause.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20274
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #8 on: July 29, 2020, 08:40:01 PM »
I have without success in creating a crash in Standard unfortunately (or possibly fortunately)! Have tried to trace it a little in Extended but likewise can’t see the obvious cause.

Very odd. If anyone is ever able to find the divergence, it would be helpful to know where it arises.

I have to say, I was mystified by the intent of the code in Standard: that I modified: it appeared to be designed to allow a crossing to be built on a bridge ramp when the ramp was on a perpendicular way, which is obviously absurd; but there appear to be lines of code specifically and only for this purpose, which is part of what I commented out. I cannot understand why they were there.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: [BUG] bridgeheads can start in illegal locations
« Reply #9 on: July 30, 2020, 01:19:34 AM »
Bit of a prolonged process but currently seem to have identified that the error started occurring in August 2019 around time changes were happening to code to allow fords over some rivers but it's difficult to pinpoint exactly when
« Last Edit: July 30, 2020, 02:16:41 AM by kierongreen »

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20274
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #10 on: July 30, 2020, 10:32:13 AM »
Bit of a prolonged process but currently seem to have identified that the error started occurring in August 2019 around time changes were happening to code to allow fords over some rivers but it's difficult to pinpoint exactly when

Interesting, thank you. I was greatly hampered in my ability to look into this by not understanding the intent of the Standard code, as discussed in my previous post.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: [BUG] bridgeheads can start in illegal locations
« Reply #11 on: July 30, 2020, 10:36:04 AM »
Interesting, thank you. I was greatly hampered in my ability to look into this by not understanding the intent of the Standard code, as discussed in my previous post.
I'm still investigating (when work allows) as to exactly what change is that's causing this - haven't managed to track down the exact commit yet - that I'm learning how to use GIT on the go is probably slowing me down a bit too!

Offline Freahk

  • Devotee
  • *
  • Posts: 1336
  • Languages: DE, EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #12 on: August 27, 2020, 11:14:01 AM »
The issue seems to be back.

As a player, it doesn't seem to be possible to build such ways, but the citygrowth can.

So I suspect the exact bug as reported above was fixed, but as kierongreen mentioned, the actual issue is located elsewhere in the code.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20274
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #13 on: August 27, 2020, 11:41:35 AM »
Thank you for your report. I will need a reliable reproduction case to be able to investigate this.

Offline Phystam

  • Devotee
  • *
  • Posts: 495
  • Pak256.Ex developer
    • Pak256 wiki page
  • Languages: JP, EN, EO
Re: [BUG] bridgeheads can start in illegal locations
« Reply #14 on: September 04, 2020, 06:42:10 AM »
I made a small save game to reproduce it.
How to reproduce:
1. Grow the cities.
That's it.
https://cdn.discordapp.com/attachments/692376966070009877/751330982862520381/illegal-bridging.sve

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Moderator
  • *
  • Posts: 20274
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #15 on: September 13, 2020, 04:15:35 PM »
Thank you for that reproduction case: that is very helpful. This is actually an extremely complex problem. The system for building bridges does not seem to have any code for detecting the case where there is not enough space for start and end ramps for two successive bridges such that the only solution is to build one long bridge. In this case, it will simply assume that there is, in fact, sufficient space to build the start ramp for the second bridge and build it even if it ought not to be building it.

Initial experiments with checking for a way on the start tile in the bridge building code and not building the bridge if there be such a way does not work in that no bridges at all are built in such a case; I suspect that what is happening is that the road building code has already built a plain road in this location, so altering the bridge building code does not assist.

Unfortunately, I d not have time to investigate any further this evening.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10243
  • Languages: De,EN,JP
Re: [BUG] bridgeheads can start in illegal locations
« Reply #16 on: September 14, 2020, 04:25:23 AM »
A bridge builds always a connecting way. So the bridge builder needs to check, whather there is a crossing on the start tile. If not, then it must fail. I will look into this in standard too.

Offline freddyhayward

  • Devotee
  • *
  • Posts: 437
  • Languages: EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #17 on: September 14, 2020, 04:31:24 AM »
The player can't build bridges in this way, so why can towns? And why do they need to build successive bridges?

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10243
  • Languages: De,EN,JP
Re: [BUG] bridgeheads can start in illegal locations
« Reply #18 on: September 14, 2020, 06:57:58 AM »
At least standard cannot cross railsway and checks for the end tile, if it is possible. I wonder if there needs to be unowned tracks for this.

Offline Freahk

  • Devotee
  • *
  • Posts: 1336
  • Languages: DE, EN
Re: [BUG] bridgeheads can start in illegal locations
« Reply #19 on: September 14, 2020, 09:35:00 AM »
I wonder if there needs to be unowned tracks for this.
Nope, I'm the owner of those tracks in the image.

The behavior of standard and extended in way construction is slightly different. I don't know when and why it diverged.
For example extended can build (useful but ugly looking) diagonal level crossings.
Further, new bridges in extended won't connect to existing ways right before or after the bride.
The latter was a fix to prevent the construction of some illegal level crossings, e.g. waterway-railway if none is defined.
It feels like in extended, there is an issue in the code that checks if a way can be built, which was then attempted to be fixed in many other locations.