Skip to content

bugfix(watertracks): Correct the path handling for .wak files in the WaterTracksRenderSystem#2634

Merged
xezon merged 1 commit intoTheSuperHackers:mainfrom
Mauller:Mauller/fix-water-track-file-load
May 1, 2026
Merged

bugfix(watertracks): Correct the path handling for .wak files in the WaterTracksRenderSystem#2634
xezon merged 1 commit intoTheSuperHackers:mainfrom
Mauller:Mauller/fix-water-track-file-load

Conversation

@Mauller
Copy link
Copy Markdown

@Mauller Mauller commented Apr 19, 2026

Closes: #2633

Merge After: #2635

This fixes a file loading issue which was introduced by a regression in #1808

The functionality that was overlooked was the original code truncating the .map extension from the file name.

We now use the AsciiString::truncateBy() AsciiString::removeExtensions() TheFileSystem::removeExtension() function to remove the .map extension before copying the ascii string.

@Mauller Mauller self-assigned this Apr 19, 2026
@Mauller Mauller added Bug Something is not working right, typically is user facing ThisProject The issue was introduced by this project, or this task is specific to this project Fix Is fixing something, but is not user facing labels Apr 19, 2026
Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp Outdated
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 19, 2026

Greptile Summary

This PR fixes a regression from #1808 in WaterTracksRenderSystem::saveTracks() and loadTracks(), where the old code appended .wak directly onto the full filename (producing mapname.map.wak) instead of first stripping the .map extension. The fix replaces the fixed 256-byte char buffer + strlcpy/strlcat pattern with FileSystem::removeExtension(fileName) followed by fileName.concat(".wak"), which correctly yields mapname.wak.

Confidence Score: 5/5

Safe to merge — the fix is correct, consistent across both call sites, and eliminates a buffer-size risk.

No P0 or P1 findings. The static FileSystem::removeExtension correctly strips the dot-extension via pointer arithmetic before the new extension is appended, and this pattern is applied identically in both saveTracks and loadTracks.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp Correctly replaces fixed-size char buffer + strlcpy/strlcat with FileSystem::removeExtension + AsciiString::concat in both saveTracks and loadTracks; fix is consistent, logically sound, and eliminates the 256-byte buffer truncation risk.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant WaterTracksRenderSystem
    participant TerrainLogic
    participant FileSystem

    Caller->>WaterTracksRenderSystem: saveTracks() / loadTracks()
    WaterTracksRenderSystem->>TerrainLogic: getSourceFilename()
    TerrainLogic-->>WaterTracksRenderSystem: "Maps/MyMap.map"
    WaterTracksRenderSystem->>FileSystem: removeExtension(fileName)
    Note over FileSystem: strrchr finds '.' → truncateTo drops ".map"
    FileSystem-->>WaterTracksRenderSystem: fileName = "Maps/MyMap"
    WaterTracksRenderSystem->>WaterTracksRenderSystem: fileName.concat(".wak")
    Note over WaterTracksRenderSystem: fileName = "Maps/MyMap.wak"
    WaterTracksRenderSystem->>FileSystem: openFile("Maps/MyMap.wak", READ|BINARY)
Loading

Reviews (4): Last reviewed commit: "fix(W3DWaterTracks): Correct the path ha..." | Re-trigger Greptile

Comment thread Core/GameEngineDevice/Source/W3DDevice/GameClient/Water/W3DWaterTracks.cpp Outdated
@Mauller
Copy link
Copy Markdown
Author

Mauller commented Apr 19, 2026

I have made a new PR to extend the functionality of AsciiString and UnicodeString with a removeExtensions() function that will remove all file extensions from a path.

The implementation relies on looking for the first full stop symbol denoting the first extension in the path name.
It then truncates the entire string up to this point.

I tested it by substituting it in where i was performing the fileName.truncateBy(sizeof(".map") - 1); and it worked for AsciiStrings. UnicodeString should work the same.

@Mauller Mauller force-pushed the Mauller/fix-water-track-file-load branch from 63a5787 to 6b30b99 Compare April 30, 2026 20:19
@Mauller
Copy link
Copy Markdown
Author

Mauller commented Apr 30, 2026

Updated the implementation after all of the new file extension handling code was merged.

The comparison will be large but the change is simple to just see in the change screen.

Also waves!
image

@Mauller Mauller force-pushed the Mauller/fix-water-track-file-load branch from 6b30b99 to 30ebc7d Compare April 30, 2026 20:25
@Mauller
Copy link
Copy Markdown
Author

Mauller commented Apr 30, 2026

Updated the implementation to remove the raw c-string handling.

@xezon xezon changed the title fix(W3DWaterTracks): Correct the path handling for .wak files in the WaterTracksRenderSystem fix(watertracks): Correct the path handling for .wak files in the WaterTracksRenderSystem Apr 30, 2026

strlcpy(path, fileName.str(), ARRAY_SIZE(path));
strlcat(path, ".wak", ARRAY_SIZE(path));
TheFileSystem->removeExtension(fileName);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

or FileSystem::removeExtension

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.

Oh yes, i forgot i made it static.

@xezon xezon added Gen Relates to Generals ZH Relates to Zero Hour and removed Fix Is fixing something, but is not user facing labels Apr 30, 2026
@Mauller Mauller force-pushed the Mauller/fix-water-track-file-load branch from 30ebc7d to 915dff1 Compare April 30, 2026 21:13
@Mauller
Copy link
Copy Markdown
Author

Mauller commented Apr 30, 2026

Tweaked to call the static function on the class instead of the instance of the file system.

@xezon xezon changed the title fix(watertracks): Correct the path handling for .wak files in the WaterTracksRenderSystem bugfix(watertracks): Correct the path handling for .wak files in the WaterTracksRenderSystem May 1, 2026
@xezon xezon merged commit 0a65107 into TheSuperHackers:main May 1, 2026
17 checks passed
@xezon xezon deleted the Mauller/fix-water-track-file-load branch May 1, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Gen Relates to Generals ThisProject The issue was introduced by this project, or this task is specific to this project ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.wak files are not loaded correctly

2 participants