Skip to content

bugfix(worldbuilder): Fix script condition selection when editing newly created condition#2289

Merged
xezon merged 2 commits intoTheSuperHackers:mainfrom
ViTeXFTW:fix/wb-update-script-index
Feb 13, 2026
Merged

bugfix(worldbuilder): Fix script condition selection when editing newly created condition#2289
xezon merged 2 commits intoTheSuperHackers:mainfrom
ViTeXFTW:fix/wb-update-script-index

Conversation

@ViTeXFTW
Copy link

@ViTeXFTW ViTeXFTW commented Feb 10, 2026

Update
The only issue was the m_index not being updated in the setSel() function - the reason for the confusion was improper build directory after the first fix was added. Resolved with deleted build dir and recompilation.

Description
This PR fixes an issue in WorldBuilder where the addition of a new condition in the script modal didn't update the m_index and left it stale. Which resulted in incorrect update of condition after editing the condition again immidiatly.

Root Cause

  1. Missing index update in setSel(). When it was called to select a newly created condition, it updated the visual selection and pointer members (m_orCondition, m_condition) but failed to update m_index. This left m_index stale.

2. Incorrect OrCondition saved in OnNew(). When adding a condition with no selection, OnNew() saved m_orCondition (which was nullptr) instead of the first OrCondition from the script. After loadList() triggered OnSelchangeConditionList(), setSel(nullptr, pCond) failed to find a match and exited without updating any state.

Fix in ScriptConditions.cpp

  1. setSel(): added m_index = count; in
    if (m_orCondition==pOr && pCond==nullptr) {
    pList->SetCurSel(count);
    m_index = count;
    enableUI();
    return;
    }

    if (m_condition == pCond) {
    pList->SetCurSel(count);
    m_index = count;
    enableUI();
    return;
    }

2. OnNew(): added *pSavOr = m_orCondition ? m_orCondition : m_script->getOrCondition();

@greptile-apps
Copy link

greptile-apps bot commented Feb 10, 2026

Greptile Overview

Greptile Summary

This PR fixes a state synchronization bug in the WorldBuilder's script condition editor. When setSel() was called to select a newly created condition (e.g., after OnNew()), it correctly updated the visual selection (pList->SetCurSel(count)) and pointer members (m_orCondition, m_condition), but failed to update m_index. This left m_index pointing to the previously selected item's index.

The bug manifested when editing a newly created condition immediately after creation - the editor would update the wrong list entry because it used the stale m_index value in operations like DeleteString(m_index) and InsertString(m_index, ...).

Fix: Added m_index = count; at both return points in setSel() where a match is found (lines 169 and 178), ensuring the index stays synchronized with the visual selection and pointer state.

Files Changed:

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is a straightforward state synchronization correction that adds two missing index assignments. The changes are minimal (2 lines per file), logically sound, and directly address the root cause. The fix matches the existing pattern used in OnSelchangeConditionList() which already sets m_index = count; when updating selection. Both vanilla and Zero Hour versions receive identical fixes, maintaining code parity.
  • No files require special attention

Important Files Changed

Filename Overview
Generals/Code/Tools/WorldBuilder/src/ScriptConditions.cpp Fixed missing m_index updates in setSel() to keep index state consistent with visual selection
GeneralsMD/Code/Tools/WorldBuilder/src/ScriptConditions.cpp Fixed missing m_index updates in setSel() to keep index state consistent with visual selection

Last reviewed commit: 7023b4b

@xezon xezon changed the title bugfix(worldbuilder): Fix script condition selection when editing newly created condition (#2066) bugfix(worldbuilder): Fix script condition selection when editing newly created condition Feb 10, 2026
@xezon xezon added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker WorldBuilder Relates to World Builder GUI For graphical user interface labels Feb 10, 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.

It's difficult to understand if this is connect. Can someone else review this?

@Caball009
Copy link

It's difficult to understand if this is connect. Can someone else review this?

I can take a look at it later.

@Caball009
Copy link

Caball009 commented Feb 11, 2026

First change looks right and directly related to the issue. Not so sure about the second change. Is there a visual cue that there's an issue if the second change isn't implemented?

@ViTeXFTW
Copy link
Author

ViTeXFTW commented Feb 11, 2026

Not so sure about the second change. Is there a visual cue that there's an issue if the second change isn't implemented?

I will do some more testing and provide an update.

I also initially thought that the first change would fix the behavior however when I recompiled, I still observed the same behavior - however I didn't do a clean rebuild of the codebase at each of the change points, but that shouldn't have an impact right?

@ViTeXFTW ViTeXFTW force-pushed the fix/wb-update-script-index branch from a4f89bc to c1ec279 Compare February 11, 2026 19:35
@ViTeXFTW
Copy link
Author

@Caball009 I've updated the PR to only contain the first fix - the issue was with the recompilation as per the updated PR text.

Copy link

@Caball009 Caball009 left a comment

Choose a reason for hiding this comment

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

Looks correct.

Needs to be replicated in Generals.

@xezon xezon merged commit 1af9a23 into TheSuperHackers:main Feb 13, 2026
24 checks passed
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 GUI For graphical user interface Minor Severity: Minor < Major < Critical < Blocker WorldBuilder Relates to World Builder

Projects

None yet

Development

Successfully merging this pull request may close these issues.

World Builder: Editing a newly created map script condition changes another condition

3 participants