OpenRCT2 / OpenRCT2/OpenRCT2

Bug: grid lines do not show in certain circumstances

Open
#13,372 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
16.2k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
80

Description

There are two issues with the grid lines not showing up when they should.

First issue

To reproduce the first issue, do one of:

  • Place a shop while auto-open is enabled.

or

  • Open the construction window for any shop or ride, including flat rides, excluding prebuilt coasters, then, without placing anything, do one of:
    • Press the Escape key.
    • Open the scenery or footpath placement window.
    • Open the construction window for anything else.
    • Many more. Basically: activate another tool.

Now, the gridlines will not be shown and will never show up again until the game is reloaded.
Note that enabling gridlines in the config still overwrites this.

The cause for this issue is in RideConstruction.cpp L613 and L627, which leads to hide_gridlines() being called twice, which in turn sets Viewport->gShowGridLinesRefCount to a negative value.
gShowGridLinesRefCount is a number (and not a boolean) because apparently when activating another tool, first the new tool is activated, then the old tool is deactivated. So, in the scenarios above, the counter goes from 0 to 1 to 2, and then back to 0 (because hide is called twice), while the second tool is still active. When the second tool is deactivated, the counter goes down to -1.

Second issue

The second issue is maybe more of a problem of the plugin API, but I believe that they are connected. If a custom tool is activated, its onStart method is called before the current tool is cancelled.

  1. Open the scenery window or a construction window so that grid lines are shown.
  2. Activate a custom tool with the plugin API, where, in the onStart method, the gridlines flag is set.

The expected result should be, that the first tool is deactivated first, then the onStart method is called and sets the gridlines flag. In reality, it happens the other way around and the flag is overwritten in the hide_gridlines() method.

Common problem and possible solution

While these two issues could be fixed in different, independent ways, I think that they both have the same core problem:
The second tool is activated before the first tool is deactivated.

If this is fixed, the second issue is solved immediately, while the first issue could then be fixed by substituting gShowGridLinesRefCount with a boolean.

June 2023 Update

The current state of this issue seems to be the following:

Option Gridlines on Landscape disabled:

  • Open tool such that gridlines show (construction windows, see above).
  • Activate custom tool that sets gridlines flag.

Expected: Gridlines stay visible.
Observed: Gridlines disappear.

Option Gridlines on Landscape enabled:

  • Execute ui.mainViewport.visibilityFlags ^= (1 << 7)

Expected: Gridlines stay visible.
Observed: Gridlines disappear.

Option Gridlines on Landscape enabled:

  • Open tool such that gridlines show (construction windows, see above).
  • Disable option Gridlines on Landscape.

Expected: Gridlines stay visible.
Observed: Gridlines disappear.

Note: In all cases, gridlines do not break, they still appear if you switch to any other tool that activates them.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in RideConstruction.cpp around lines 613 and 627, then trace hide_gridlines() and Viewport->gShowGridLinesRefCount through tool activation and cancellation. Reproduce the listed construction-window and custom-tool scenarios, including the Gridlines on Landscape option. Done means gridlines remain visible whenever the reported expected conditions hold and do not become permanently hidden after tool changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.