Skip to content

bugfix(worldbuilder): Fix uncaught carriage return in CommandButton name when parsing from INI#2300

Open
ViTeXFTW wants to merge 2 commits intoTheSuperHackers:mainfrom
ViTeXFTW:fix/wb-false-cb-script-error
Open

bugfix(worldbuilder): Fix uncaught carriage return in CommandButton name when parsing from INI#2300
ViTeXFTW wants to merge 2 commits intoTheSuperHackers:mainfrom
ViTeXFTW:fix/wb-false-cb-script-error

Conversation

@ViTeXFTW
Copy link

@ViTeXFTW ViTeXFTW commented Feb 13, 2026

Description
This PR fixes an issue in WorldBuilder where CommandButton validation incorrectly reports "Command button does not exist" errors when using the Add a CommandButton to an object type. The issue occurs when CommandButton names are loaded from INI files - the names contain trailing carriage return characters from Windows line endings, causing string comparisons to fail even though the buttons exist and display correctly in the UI.

This means for mappers they get a visual indication that their script has an error when the CommandButton name is correct and a false positive when the CommandButton name still has the trailing carriage return.

Root Cause
The strtok delimiter array in loadCommandButtons() only included " ,\t\n"

Fix in EditParameter.cpp. In loadCommandButtons(): added \r to the delimiter.

Old:
image

New:
image

TODO

  • Replicate in Generals

@greptile-apps
Copy link

greptile-apps bot commented Feb 13, 2026

Greptile Summary

Adds \r (carriage return) to the strtok delimiter string in loadCommandButtons() for both the Generals and GeneralsMD versions of EditParameter.cpp. This fixes false "Command button does not exist" validation errors in WorldBuilder caused by trailing \r characters from Windows-style line endings (\r\n) in INI files not being stripped during tokenization.

  • Added \r to the seps delimiter array in Generals/Code/Tools/WorldBuilder/src/EditParameter.cpp
  • Added \r to the seps delimiter array in GeneralsMD/Code/Tools/WorldBuilder/src/EditParameter.cpp
  • The fix is consistent with how ParticleSys.cpp already handles the same issue with its own seps array
  • loadCommandButtons() is the only load function in EditParameter.cpp that parses INI files directly with strtok; other load functions use in-memory stores and are not affected

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, well-understood one-character bugfix applied consistently to both game variants.
  • The change adds a single character (\r) to a delimiter string in two parallel files. The fix is correct: strtok needs \r as a delimiter to handle Windows CRLF line endings. The change is consistent with existing patterns in the codebase (e.g., ParticleSys.cpp). No other code paths are affected. Risk of regression is effectively zero.
  • No files require special attention.

Important Files Changed

Filename Overview
GeneralsMD/Code/Tools/WorldBuilder/src/EditParameter.cpp Single-character addition of \r to strtok delimiter string in loadCommandButtons() — correct and safe fix for carriage return stripping.
Generals/Code/Tools/WorldBuilder/src/EditParameter.cpp Identical single-character addition of \r to strtok delimiter string in loadCommandButtons() — mirrors the GeneralsMD fix.

Flowchart

flowchart TD
    A["loadCommandButtons() called"] --> B["Open CommandButton.ini"]
    B --> C["Read line into buf via nextLine()"]
    C --> D["Tokenize with strtok(buf, seps)"]
    D --> E{"Token == 'CommandButton'?"}
    E -->|Yes| F["Get next token (button name)"]
    F --> G{"Before fix:\nseps = ' ,\\t\\n'"}
    F --> H{"After fix:\nseps = ' ,\\t\\n\\r'"}
    G --> I["Token retains trailing \\r\ne.g. 'ButtonName\\r'"]
    H --> J["Token is clean\ne.g. 'ButtonName'"]
    I --> K["strcmp fails → false 'does not exist' error"]
    J --> L["strcmp succeeds → correct validation"]
Loading

Last reviewed commit: 9bc2c9a

in loadCommandButton seperator

Co-authored-by: AdrianeYves
@ViTeXFTW ViTeXFTW force-pushed the fix/wb-false-cb-script-error branch from 03d1d5b to fdbdad3 Compare February 13, 2026 15:00
@xezon xezon added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker WorldBuilder Relates to World Builder Script Is related to Script Engine, SCB and removed Script Is related to Script Engine, SCB labels Feb 15, 2026
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

The title needs to say what this fixes.

@ViTeXFTW ViTeXFTW changed the title bugfix(worldbuilder): Add carriage return to delimiter array in loadCommandButtons tokenization bugfix(worldbuilder): fix wrong CommandButton string when loading from ini files Feb 15, 2026
@ViTeXFTW ViTeXFTW changed the title bugfix(worldbuilder): fix wrong CommandButton string when loading from ini files bugfix(worldbuilder): fix wrong CommandButton string parsing when loading from ini files Feb 15, 2026
@ViTeXFTW ViTeXFTW changed the title bugfix(worldbuilder): fix wrong CommandButton string parsing when loading from ini files bugfix(worldbuilder): fix uncaught carriage return in CommandButton name when parsing from ini Feb 16, 2026
@xezon
Copy link

xezon commented Feb 16, 2026

Needs to be replicated to Generals.

@xezon xezon changed the title bugfix(worldbuilder): fix uncaught carriage return in CommandButton name when parsing from ini bugfix(worldbuilder): Fix uncaught carriage return in CommandButton name when parsing from INI Feb 16, 2026
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 Minor Severity: Minor < Major < Critical < Blocker WorldBuilder Relates to World Builder

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worldbuilder: adding/removing command buttons have an invisible character, causing the script to appear with an error

2 participants