Skip to content

bugfix(w3droadbuffer): Ensure road type buffer fits all roads from Roads.ini - #3731

Open
Jaredl-Dev wants to merge 3 commits into
TheSuperHackers:mainfrom
Jaredl-Dev:fix/w3droadbuffer-max-road-types
Open

Jaredl-Dev wants to merge 3 commits into
TheSuperHackers:mainfrom
Jaredl-Dev:fix/w3droadbuffer-max-road-types

Conversation

@Jaredl-Dev

Copy link
Copy Markdown

Closes #3729
Depends on #3730

Cause

Retail Generals GameData.ini sets MaxRoadTypes = 35 while Roads.ini defines 36 roads. Because TerrainRoadCollection::newRoad() prepends to m_roadList, TwoLane (first in Roads.ini) is visited 36th and skipped in W3DRoadBuffer::allocateRoadBuffers(). This was previously masked in Release builds by LOAD_TEST_ASSETS adding 4 to m_maxRoadTypes before #1485 restricted it to debug builds.

Fix

In W3DRoadBuffer::allocateRoadBuffers(), count the roads in TheTerrainRoads and raise m_maxRoadTypes to at least that count before allocating m_roadTypes.

Verification

  • Verified TwoLane roads render on Alpine Assault in a VC6 Release build of Generals.
  • Verified VC6 and Win32 Release builds pass.

@Jaredl-Dev
Jaredl-Dev force-pushed the fix/w3droadbuffer-max-road-types branch from 74ae9c4 to 5fcbb7c Compare November 27, 2026 21:28
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The W3D road-buffer implementation is registered in Core and removed from the Generals build paths. Its allocation logic now raises the road-type capacity to match the number of defined roads when that count is larger.

Changes

W3D Road Buffer

Layer / File(s) Summary
Move road buffer into Core
Generals/Code/GameEngineDevice/.../W3DRoadBuffer.*, Core/GameEngineDevice/.../W3DRoadBuffer.cpp, Core/GameEngineDevice/CMakeLists.txt, Generals/Code/GameEngineDevice/CMakeLists.txt, GeneralsMD/Code/GameEngineDevice/CMakeLists.txt, scripts/cpp/unify_move_files.py
The road-buffer header and implementation are removed from the Generals source tree and registered in Core. Generals and GeneralsMD build lists exclude them. The file-mapping entries remain commented out.
Size buffers for defined roads
Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp
allocateRoadBuffers counts the road definitions and raises m_maxRoadTypes when the count is larger. It does so before allocating the road-type array.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: xezon, bobtista

Merge Risk: Minimal · up to 5fcbb

This change moves the road buffer into shared Core code and sizes its road-type array to the number of defined roads. That restores the missing TwoLane roads in Generals Release builds. No concrete merge-blocking risk was found, and the builds and in-game check reported by the author support it.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (ensuring the road type buffer fits all roads from Roads.ini) and the component (w3droadbuffer). The changeset raises m_maxRoadTypes in W3DRoadBuffer::allocateRoadBuffers() to …
Description check Passed The description states the cause (Generals MaxRoadTypes = 35 versus 36 roads in Roads.ini, with TwoLane skipped), the fix (counting roads in TheTerrainRoads and raising m_maxRoadTypes before allocatin…
Linked Issues check Passed Directly linked issue #3729 has one coding requirement: TwoLane roads must render in Generals Release builds. The stated cause is that MaxRoadTypes (35) is lower than the road count (36), so TwoLane i…
Out of Scope Changes check Passed The change set has four groups. (1) The fix in Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp implements #3729 directly. (2) Moving W3DRoadBuffer.h and W3DRoadBuffer.cpp from Gene…
Full details: Title check

Explanation

The title names the fix (ensuring the road type buffer fits all roads from Roads.ini) and the component (w3droadbuffer). The changeset raises m_maxRoadTypes in W3DRoadBuffer::allocateRoadBuffers() to the count of roads in TheTerrainRoads, which matches the title. The title is specific and describes the primary change. It also carries a 'bugfix' prefix that fits the linked issue about missing TwoLane roads.

Full details: Description check

Explanation

The description states the cause (Generals MaxRoadTypes = 35 versus 36 roads in Roads.ini, with TwoLane skipped), the fix (counting roads in TheTerrainRoads and raising m_maxRoadTypes before allocating m_roadTypes), and the verification steps. It relates directly to the changeset, so it passes this lenient check.

Full details: Linked Issues check

Explanation

Directly linked issue #3729 has one coding requirement: TwoLane roads must render in Generals Release builds. The stated cause is that MaxRoadTypes (35) is lower than the road count (36), so TwoLane is skipped in W3DRoadBuffer::allocateRoadBuffers(). The change set addresses this cause. Per the change summary, allocateRoadBuffers() counts the roads in TheTerrainRoads and raises m_maxRoadTypes to at least that count before allocating m_roadTypes. This removes the off-by-one limit for Generals. Zero Hour is not affected, as stated in the issue. The author reports a Release build check on Alpine Assault. That report is not independently verified here. No unresolved coding requirement remains in the evidence reviewed. The inspection was limited to the change summary; the head implementation of allocateRoadBuffers() was not read line by line.

Full details: Out of Scope Changes check

Explanation

The change set has four groups. (1) The fix in Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp implements #3729 directly. (2) Moving W3DRoadBuffer.h and W3DRoadBuffer.cpp from Generals/Code and GeneralsMD/Code to Core, with CMake updates, lets Generals and Zero Hour share one fixed implementation. This supports the fix and is a required part of it. (3) Removing the Generals copies from the Generals CMake source list, and commenting out the Zero Hour CMake entries, are needed to avoid duplicate compilation after the move. (4) The disabled unify_file entries in scripts/cpp/unify_move_files.py record the file move. They do not change build or runtime behavior. The change summary shows no unrelated functional change. Moved code does not add new behavior outside the road-buffer path.

Warning

Some tools did not complete. Review the errors below.

Clang (23.1.4)

Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp

Clang-Tidy produced no recognizable diagnostics; analysis is incomplete

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c25e689a-98b8-4096-abf2-f99939068b1a
Commits

Reviewing files that changed from the base of the PR and between 9afbe5c and 5fcbb7c.

Files selected for processing: 8

  • Core/GameEngineDevice/CMakeLists.txt
  • Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DRoadBuffer.h
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp
  • Generals/Code/GameEngineDevice/CMakeLists.txt
  • Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DRoadBuffer.h
  • Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp
  • GeneralsMD/Code/GameEngineDevice/CMakeLists.txt
  • scripts/cpp/unify_move_files.py
Files with no reviewable changes: 2

  • Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DRoadBuffer.h
  • Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DRoadBuffer.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no new actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR moves W3DRoadBuffer into Core and makes its road-type array large enough for every defined road.

  • Road buffers now fit every road listed in Roads.ini.

Reviews (2) · Last reviewed commit: "bugfix(w3droadbuffer): Ensure road type ..." · Reviewed by Greptile

// TheSuperHackers @bugfix Jaredl-Dev 27/11/2026 Ensure m_maxRoadTypes fits all roads defined in Roads.ini.
TerrainRoadType *road;
Int roadCount = 0;
for( road = TheTerrainRoads->firstRoad(); road; road = TheTerrainRoads->nextRoad( road ) )

@Skyaero42 Skyaero42 Nov 28, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think

Int roadCount = 0;
TerrainRoadType *road =TheTerrainRoads->firstRoad();
do {
    roadCount++;
}
while (road = TheTerrainRoads->nextRoad( road ))

is cleaner, although that may be personal.

I do think the counting of roads needs to be done in the TerrainRoadCollection and then call TheTerrainRoads->roadCount(). Standard collection types like lists usually provide a count as well and it looks cleaner

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move the count into TerrainRoadCollection. How about a roadCount() method that walks m_roadList?

Int TerrainRoadCollection::roadCount()
{
	Int count = 0;
	for( TerrainRoadType *road = m_roadList; road; road = nextRoad( road ) )
		++count;
	return count;
}

allocateRoadBuffers() would then raise m_maxRoadTypes to TheTerrainRoads->roadCount() when it's lower.

With the do/while, couldn't it possibly end up calling nextRoad() with a null pointer? If no roads are defined, firstRoad() returns null, but the body still runs once and then calls nextRoad( nullptr ).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposal looks to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Generals] TwoLane roads fail to render in Release builds

2 participants