Skip to content

fix(debug): Allocate enough terrain debug icons based on the map dimensions in W3DDebugIcons()#2231

Merged
xezon merged 1 commit intoTheSuperHackers:mainfrom
Mauller:Mauller/increase-max-debug-icons-drawable
Feb 7, 2026
Merged

fix(debug): Allocate enough terrain debug icons based on the map dimensions in W3DDebugIcons()#2231
xezon merged 1 commit intoTheSuperHackers:mainfrom
Mauller:Mauller/increase-max-debug-icons-drawable

Conversation

@Mauller
Copy link

@Mauller Mauller commented Jan 31, 2026

Edit: Updated the PR to now allocate based on the map dimensions.

A simple PR that helps with debugging pathfinding and other systems that draw overlay tiles on the map.

In some instances the defaulT 100k tiles is not enought, resulting in areas of the map missing debug icons.

The following example is an extreme case, but i have seen some complex maps where parts of the map are missing debug icons on the terrain before any buildings are constructed.

Before:
image
image

After:
image
image

@Mauller Mauller self-assigned this Jan 31, 2026
@Mauller Mauller added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Debug Is mostly debug functionality Fix Is fixing something, but is not user facing labels Jan 31, 2026
@greptile-apps
Copy link

greptile-apps bot commented Jan 31, 2026

Greptile Overview

Greptile Summary

Changed debug icon allocation from a fixed 100k array to dynamic sizing based on map dimensions (mapWidth * mapHeight). This ensures sufficient debug icons for large maps while avoiding wasted memory on smaller maps.

Key Changes:

  • Constructor now accepts mapWidth and mapHeight parameters
  • Replaced MAX_ICONS constant with m_maxDebugIcons member variable
  • Fixed array deletion from delete to delete[] (previously undefined behavior)
  • Added assertion to prevent double allocation
  • Updated instantiation in W3DTerrainVisual to pass map dimensions from height map

Improvements:

  • Fixes debug icon shortages on large/complex maps
  • Corrects memory management bug (delete vs delete[])
  • More efficient memory usage for smaller maps

Confidence Score: 4/5

  • Safe to merge with low risk - fixes actual bug and improves debug functionality
  • The changes are well-contained and improve the debug system. The delete[] fix corrects undefined behavior. The dynamic allocation based on map size is sensible. Score reduced from 5 due to the existing copy constructor not being updated to initialize the new m_maxDebugIcons member, though this was already broken and unlikely to be used in practice.
  • No files require special attention

Important Files Changed

Filename Overview
Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp Implemented dynamic allocation based on map size, fixed delete to delete[], added allocation assertion
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp Implemented dynamic allocation based on map size, fixed delete to delete[], added allocation assertion

Sequence Diagram

sequenceDiagram
    participant TV as W3DTerrainVisual
    participant HM as LogicHeightMap
    participant DI as W3DDebugIcons
    participant Arr as DebugIcon Array (static)
    
    TV->>HM: getXExtent()
    HM-->>TV: mapWidth
    TV->>HM: getYExtent()
    HM-->>TV: mapHeight
    TV->>DI: NEW W3DDebugIcons(mapWidth, mapHeight)
    activate DI
    DI->>DI: m_maxDebugIcons = mapWidth * mapHeight
    DI->>DI: allocateIconsArray()
    DI->>Arr: NEW DebugIcon[m_maxDebugIcons]
    Arr-->>DI: allocated array
    DI->>DI: m_numDebugIcons = 0
    deactivate DI
    TV->>DI: Release_Ref() (belongs to scene)
Loading

@Mauller Mauller force-pushed the Mauller/increase-max-debug-icons-drawable branch from 1f397d1 to 3aae899 Compare February 2, 2026 21:29
@Mauller
Copy link
Author

Mauller commented Feb 2, 2026

Updated to size the number of debug icons based on the size of the map

@Mauller Mauller changed the title tweak(debug): Increase the number of drawable debug icons by a factor of 10 in W3DDebugIcons() tweak(debug): Allocate debug icons based on the map dimensions in W3DDebugIcons() Feb 2, 2026
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@Mauller Mauller force-pushed the Mauller/increase-max-debug-icons-drawable branch from 3aae899 to a93d8a5 Compare February 3, 2026 17:32
@Mauller
Copy link
Author

Mauller commented Feb 3, 2026

Tweaked the implementation to remove some of the variables that were redundant

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link

greptile-apps bot commented Feb 3, 2026

Additional Comments (2)

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp
Should reset m_maxDebugIcons = 0 for consistency with other static members

	m_maxDebugIcons = 0;

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp
Line: 105:105

Comment:
Should reset `m_maxDebugIcons = 0` for consistency with other static members

```suggestion
	m_maxDebugIcons = 0;
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp
Should reset m_maxDebugIcons = 0 for consistency with other static members

	m_maxDebugIcons = 0;

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp
Line: 105:105

Comment:
Should reset `m_maxDebugIcons = 0` for consistency with other static members

```suggestion
	m_maxDebugIcons = 0;
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@Mauller Mauller force-pushed the Mauller/increase-max-debug-icons-drawable branch from a93d8a5 to 01cdaad Compare February 3, 2026 21:07
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link

greptile-apps bot commented Feb 3, 2026

Additional Comments (2)

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp
[P0] Mismatched delete for array allocation

m_debugIcons is allocated with NEW DebugIcon[m_maxDebugIcons] in allocateIconsArray() but freed with delete m_debugIcons in the destructor. If NEW maps to normal new, this should be delete[] to avoid undefined behavior (bad destructor call / heap corruption depending on allocator).

Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp
Line: 100:104

Comment:
[P0] Mismatched delete for array allocation

`m_debugIcons` is allocated with `NEW DebugIcon[m_maxDebugIcons]` in `allocateIconsArray()` but freed with `delete m_debugIcons` in the destructor. If `NEW` maps to normal `new`, this should be `delete[]` to avoid undefined behavior (bad destructor call / heap corruption depending on allocator).

How can I resolve this? If you propose a fix, please make it concise.

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp
[P0] Mismatched delete for array allocation

Same issue as Generals variant: m_debugIcons is allocated with NEW DebugIcon[m_maxDebugIcons] but freed with delete m_debugIcons. If NEW maps to normal new, this must be delete[] to avoid UB / heap corruption.

Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDebugIcons.cpp
Line: 100:104

Comment:
[P0] Mismatched delete for array allocation

Same issue as Generals variant: `m_debugIcons` is allocated with `NEW DebugIcon[m_maxDebugIcons]` but freed with `delete m_debugIcons`. If `NEW` maps to normal `new`, this must be `delete[]` to avoid UB / heap corruption.

How can I resolve this? If you propose a fix, please make it concise.

@Mauller Mauller force-pushed the Mauller/increase-max-debug-icons-drawable branch from 01cdaad to 3d2bace Compare February 3, 2026 21:13
@Mauller
Copy link
Author

Mauller commented Feb 3, 2026

Updated based on review comments

@xezon
Copy link

xezon commented Feb 3, 2026

Greptile is complaining about a copy constructor:

Score reduced from 5 due to the existing copy constructor not being updated to initialize the new m_maxDebugIcons member, though this was already broken and unlikely to be used in practice.

@Mauller
Copy link
Author

Mauller commented Feb 7, 2026

Greptile is complaining about a copy constructor:

Score reduced from 5 due to the existing copy constructor not being updated to initialize the new m_maxDebugIcons member, though this was already broken and unlikely to be used in practice.

I think it's hallucinating since that variable is static anyway

@xezon xezon changed the title tweak(debug): Allocate debug icons based on the map dimensions in W3DDebugIcons() fix(debug): Allocate enough terrain debug icons based on the map dimensions in W3DDebugIcons() Feb 7, 2026
@xezon xezon merged commit 8e6360e into TheSuperHackers:main Feb 7, 2026
25 checks passed
@xezon xezon deleted the Mauller/increase-max-debug-icons-drawable branch February 7, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Debug Is mostly debug functionality Fix Is fixing something, but is not user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants