[2.0.14] Rail signal selection rectangle does not match actual selectable area

Post your bugs and problems so we can fix them.
robot256
Smart Inserter
Smart Inserter
Posts: 1063
Joined: Sun Mar 17, 2019 1:52 am
Contact:

[2.0.14] Rail signal selection rectangle does not match actual selectable area

Post by robot256 »

Summary of how it affects Vanilla:
When the rail signal selection box is shifted either by making selection_box offset from (0,0) or by making selection_box_shift values nonzero, the mouse-over area is correct but the highlight rectangles (and debug selection rectangle) are rendered incorrectly.

This bug can be directly observed in the vanilla rail-signal in orientations where the selection_box_shift value is significant. For example, this screenshot and clip shows the NorthEast rotation. You can see that the highlight box is centered on the tile center, not the area to the right where the mouse-over is detected. Normally this is nearly undetectable because the rail covers (and takes priority over) the part of the selection area not surrounded by the highlight box, and the vanilla selection_box_shift values are all small.
Screenshot 2024-11-03 194151.png
Screenshot 2024-11-03 194151.png (111.17 KiB) Viewed 200 times
Screen Recording 2024-11-03 194230.mp4
(692.78 KiB) Downloaded 10 times
More detailed explanation:
The effect is very pronounced when using larger shifts, and makes them unusable.

What I did:
- Set rail signal selection_box = {{-1.5, -0.5}, {-0.5, 0.5}}, so that the box is offset from the center of the collision box and the rail. I rendered the sprite for 16 directions including shifts along the required vectors.

What works:
- This behaves as expected in the North, South, East, and West orientations.
- In diagonal directions, the mouse-over region is correctly centered and rotated to follow the graphics at the set distance from the rail.
- In diagonal directions, the selection outline is rotated about its center the correct amount.
- If I alter the selection_box_shift values for the RailSignalPictureStructure, the selectable mouse-over region shifts accordingly.

What doesn't work:
- In every diagonal direction, the selection rectangle (both the yellow/green/blue highlight and the debug selection rectangle) is drawn centered on the wrong point. It is always shifted 1 tile left, the correct shift for North, rather than by a rotated vector. It does not line up with the actual region where the entity can be selected.

Graphical evidence:
These screenshots and clips show the highlight shift behavior for every rotation (with selection_box_shift set to {0,0}). Observe that for the diagonal ones, the blue selection_rectangle is always 1 tile to the left of the collision_rectangle, even though the mouse-over area moves by the proper vector to follow the sprites.
Screenshot 2024-11-03 200332.png
Screenshot 2024-11-03 200332.png (1.32 MiB) Viewed 200 times
Screenshot 2024-11-03 200522.png
Screenshot 2024-11-03 200522.png (1.79 MiB) Viewed 200 times
Screen Recording 2024-11-03 200404.mp4
(6.72 MiB) Downloaded 11 times
Screen Recording 2024-11-03 200559.mp4
(10.78 MiB) Downloaded 13 times
robot256
Smart Inserter
Smart Inserter
Posts: 1063
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [2.0.14] Rail signal selection rectangle does not match actual selectable area

Post by robot256 »

Update: Still present in 2.0.17.

Xorimuth and I dug into the source code a bit, and he found with the debugger that the mouse-detection code is correctly executing RailSignalBase::getSelectionBox, but the box-drawing code is executing Entity::getSelectionBox which does not account for asymmetric rotation and shift. We can't figure out why this would be the case, but that would certainly explain the discrepancy between actual and drawn selection area.

Edit: He found the reason. When Entity::getSelectionBox() is called instead of Entity::getSelectionBox(const SelectionContext&), it doesn't call the child class implementation. Hopefully this will be an easy fix now!

It's likely that solving this bug will also solve 119782.
Post Reply

Return to “Bug Reports”