https://github.com/libsdl-org/Maelstrom/commit/7bf85a504d9a02ddecff8caff0c92af7ff0093e7
From 7bf85a504d9a02ddecff8caff0c92af7ff0093e7 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 20 Oct 2012 01:30:06 -0700
Subject: [PATCH] Fixed more memory corruption when deleting UI elements
Clearing the anchor on anchored areas was removing them from m_anchoredAreas,
while we were iterating over it. So just iterate backwards over
m_anchoredAreas so this is safe.
---
screenlib/UIArea.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/screenlib/UIArea.cpp b/screenlib/UIArea.cpp
index afca6ff2..99593f48 100644
--- a/screenlib/UIArea.cpp
+++ b/screenlib/UIArea.cpp
@@ -43,7 +43,7 @@ UIArea::UIArea(UIArea *anchor, int w, int h) : ErrorBase()
UIArea::~UIArea()
{
SetAnchorElement(NULL);
- for (int i = 0; i < m_anchoredAreas.length(); ++i) {
+ for (int i = m_anchoredAreas.length(); i--; ) {
m_anchoredAreas[i]->SetAnchor(CENTER, CENTER, NULL);
}
}