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

Wrong bits used when converting signal types/variants while loading savegames older then v64. #5732

Closed
DorpsGek opened this issue Sep 3, 2013 · 2 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)

Comments

@DorpsGek
Copy link
Member

DorpsGek commented Sep 3, 2013

adf88 opened the ticket and wrote:

This is a dormant bug, now the code works but only through accident.

From r10006 different signals are allowed on a single tile. When loading a savegame file v63 or older signal type/variant bits (m2 bits 0..2) are being duplicated (at m2 bits 4..6). The code responsible for this is inside afterload.cpp around line 1505:

SetSignalStates(t, GB(_m[t].m2, 4, 4));
SetSignalVariant(t, INVALID_TRACK, GetSignalVariant(t, TRACK_X));
SetSignalType(t, INVALID_TRACK, GetSignalType(t, TRACK_X));
ClrBit(_m[t].m2, 7);

You can see SetSignalType and SetSignalVariant. BUT these two functions changed in r10006 when PBS'es were added, we have new functions operating on new bits. Currently signal type occupies 3 bits, not 2. Also signal variant bits changed from bit 2 to bit 3. The code works only because the signal variant bit is carried with signal type (it produces invalid signal types for a while!). It may cause whole sort of problems, especially if one tries to change signal bits again.

I'm attaching a patch to fix the issue.

Attachments

Reported version: Version?
Operating system: All


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

DorpsGek commented Sep 3, 2013

adf88 wrote:

See also #5731

HISTORY OF SIGNAL TYPE/VARIANT BITS

r13932 sl 100
add PBS signal type
signal variant:
m2 [6] -> [7]
m2 [2] -> [3]
signal type:
m2 [0..1] -> [0..2]
m2 [4..5] -> [4..6]

r10006 sl 64
allow different signals on single tile
signal type:
m2 [0..1] -> [0..1, 4..5]
signal variant:
m2 [2] -> [2, 6]

r8935 sl 48
some optimizations
signal type:
m4 [0..1] -> m2 [0..1]
signal variant:
m4 [2] -> m2 [2]

r3472 sl 21
remove PBS signal type
signal type:
m4 [0..2] -> [0..1]
signal variant:
m4 [3] -> [2]

sl 15
add PBS signal type
signal type:
m4 [0..1] -> [0..2]
signal variant:
m4 [2] -> [3]


This comment was imported from FlySpray: https://bugs.openttd.org/task/5732#comment12583

@DorpsGek
Copy link
Member Author

DorpsGek commented Nov 8, 2013

Rubidium closed the ticket.

Reason for closing: Fixed

In r25953


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

@DorpsGek DorpsGek closed this as completed Nov 8, 2013
@DorpsGek DorpsGek added Core flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) labels Apr 7, 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