bugfix(worldbuilder): Check list size before accessing first element in ObjectOptions::_FindOrDont#2306
Conversation
…in ObjectOptions::_FindOrDont.
Greptile Overview
|
| 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
Additional Comments (2)
Prompt To Fix With AIThis 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.
Prompt To Fix With AIThis 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. |
76d8bb1 to
2f5d827
Compare
| itemsToEx.push_back(startPoint); | ||
|
|
||
| while (itemsToEx.front()) { | ||
| while (!itemsToEx.empty() && itemsToEx.front()) { |
There was a problem hiding this comment.
Is HTREEITEM a pointer?
Maybe just do while (!itemsToEx.empty())? Why test for front() here?
There was a problem hiding this comment.
I agree, only testing for empty should resolve this here, as when not empty you should always have a front iterator.
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.