1
0
forked from 0ad/0ad

Prevent OOM crash in Reference Tree on error

The structTree, in case of errors, could have enough items to draw to
trigger an OOM failure in the Arena allocator.

This fixes that by hiding elements by default and some c++ memory
optimisation (mostly, this should make all platforms take the same
memory footprint for VisibleObject).

Discussed with vladislavbelov and s0600204

Differential Revision: https://code.wildfiregames.com/D4114
This was SVN commit r25746.
This commit is contained in:
wraitii 2021-06-08 14:57:59 +00:00
parent 858148d332
commit b7ff371d00
3 changed files with 5 additions and 5 deletions

View File

@ -12,7 +12,7 @@
<object type="image" style="TreeDisplay" size="0 24 100% 100%" name="trainers">
<repeat count="6" var="t">
<object type="image" style="StructBox" name="trainer[t]">
<object type="image" style="StructBox" name="trainer[t]" hidden="true">
<object type="text" style="StructNamePrimary" name="trainer[t]_name"/>
<object type="button" style="StructIcon" name="trainer[t]_icon"/>
<object name="trainer[t]_productionRows">

View File

@ -2,7 +2,7 @@
<object size="0 54+64 100%-16 100%-54" name="treeSection">
<object name="phaseIdents">
<repeat count="4" var="n">
<object name="phase[n]_ident">
<object name="phase[n]_ident" hidden="true">
<object name="phase[n]_icon" type="image" size="16 32 16+48 32+48"/>
<object name="phase[n]_bars">
<repeat count="4" var="k">
@ -17,7 +17,7 @@
<object type="image" name="structures" style="TreeDisplay" size="48+16+8 0 100% 100%">
<repeat count="40" var="s">
<object type="image" style="StructBox" name="structure[s]">
<object type="image" style="StructBox" name="structure[s]" hidden="true">
<object type="text" style="StructNamePrimary" name="structure[s]_name"/>
<object type="button" style="StructIcon" name="structure[s]_icon"/>
<object name="structure[s]_productionRows">

View File

@ -74,7 +74,7 @@ struct VisibleObject
{
IGUIObject* object;
// Index of the object in a depth-first search inside GUI tree.
size_t index;
u32 index;
// Cached value of GetBufferedZ to avoid recursive calls in a deep hierarchy.
float bufferedZ;
};
@ -86,7 +86,7 @@ void CollectVisibleObjectsRecursively(const std::vector<IGUIObject*>& objects, C
{
if (!object->IsHidden())
{
visibleObjects->emplace_back(VisibleObject{object, visibleObjects->size(), 0.0f});
visibleObjects->emplace_back(VisibleObject{object, static_cast<u32>(visibleObjects->size()), 0.0f});
CollectVisibleObjectsRecursively(object->GetChildren(), visibleObjects);
}
}