Skip to content

bugfix(worldbuilder): Check list size before accessing first element in ObjectOptions::_FindOrDont#2306

Open
Caball009 wants to merge 2 commits intoTheSuperHackers:mainfrom
Caball009:fix_world_builder_list_front
Open

bugfix(worldbuilder): Check list size before accessing first element in ObjectOptions::_FindOrDont#2306
Caball009 wants to merge 2 commits intoTheSuperHackers:mainfrom
Caball009:fix_world_builder_list_front

Conversation

@Caball009
Copy link

@Caball009 Caball009 commented Feb 15, 2026

image

If you open the map Sand Serpent with the World Builder and click on the green object in the center of the blue circle, you get a debug assertion that accessing the front element of an empty list is not allowed. This PR fixes that.

@Caball009 Caball009 added Bug Something is not working right, typically is user facing Minor Severity: Minor < Major < Critical < Blocker WorldBuilder Relates to World Builder labels Feb 15, 2026
@greptile-apps
Copy link

greptile-apps bot commented Feb 15, 2026

Greptile Overview

Greptile Summary

Fixed a debug assertion crash in World Builder when clicking on certain objects. The _FindOrDont function performed breadth-first search through a tree view but didn't check if the list was empty before calling front(), causing crashes when the tree was fully traversed.

  • Added !itemsToEx.empty() check to while loop condition in both Generals and GeneralsMD versions
  • Prevents undefined behavior when accessing front() on empty std::list
  • Fix is minimal, targeted, and identical across both codebases

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The fix is a standard defensive programming pattern that prevents undefined behavior. The change is minimal (adding !itemsToEx.empty() check), logically correct, and applied consistently to both codebases. The fix directly addresses the reported crash without introducing side effects.
  • No files require special attention

Important Files Changed

Filename Overview
Generals/Code/Tools/WorldBuilder/src/ObjectOptions.cpp Added empty list check to prevent debug assertion when accessing front element
GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp Added empty list check to prevent debug assertion when accessing front element

Last reviewed commit: 2f5d827

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

@greptile-apps
Copy link

greptile-apps bot commented Feb 15, 2026

Additional Comments (2)

Generals/Code/Tools/WorldBuilder/src/ObjectOptions.cpp
GetChildItem can return NULL when there are no children. Should add null check before pushing to list to prevent processing invalid handles.

			HTREEITEM child = m_objectTreeView.GetChildItem(hItem);
			if (child) {
				itemsToEx.push_back(child);
			}
Prompt To Fix With AI
This is a comment left during a code review.
Path: Generals/Code/Tools/WorldBuilder/src/ObjectOptions.cpp
Line: 428:428

Comment:
`GetChildItem` can return NULL when there are no children. Should add null check before pushing to list to prevent processing invalid handles.

```suggestion
			HTREEITEM child = m_objectTreeView.GetChildItem(hItem);
			if (child) {
				itemsToEx.push_back(child);
			}
```

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

GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp
GetChildItem can return NULL when there are no children. Should add null check before pushing to list to prevent processing invalid handles.

			HTREEITEM child = m_objectTreeView.GetChildItem(hItem);
			if (child) {
				itemsToEx.push_back(child);
			}
Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/Tools/WorldBuilder/src/ObjectOptions.cpp
Line: 428:428

Comment:
`GetChildItem` can return NULL when there are no children. Should add null check before pushing to list to prevent processing invalid handles.

```suggestion
			HTREEITEM child = m_objectTreeView.GetChildItem(hItem);
			if (child) {
				itemsToEx.push_back(child);
			}
```

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

@Caball009 Caball009 force-pushed the fix_world_builder_list_front branch from 76d8bb1 to 2f5d827 Compare February 15, 2026 00:48
itemsToEx.push_back(startPoint);

while (itemsToEx.front()) {
while (!itemsToEx.empty() && itemsToEx.front()) {
Copy link

Choose a reason for hiding this comment

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

Is HTREEITEM a pointer?

Maybe just do while (!itemsToEx.empty())? Why test for front() here?

Copy link

Choose a reason for hiding this comment

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

I agree, only testing for empty should resolve this here, as when not empty you should always have a front iterator.

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.

3 participants