summaryrefslogtreecommitdiff
path: root/common/piece.cpp
diff options
context:
space:
mode:
authorleo2006-02-10 07:50:14 +0000
committerleo2006-02-10 07:50:14 +0000
commit2ed469d71dcd2bf0df70713963c03569d7bd22e5 (patch)
tree73589889a70a938884b7f269cea0f9ef0fbf8a5c /common/piece.cpp
parentae0ec9c97053a0148afc6abf8da67c2e708ccf56 (diff)
Fixed a crash and rendering bug when removing pieces.
git-svn-id: http://svn.leocad.org/trunk@469 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'common/piece.cpp')
-rw-r--r--common/piece.cpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/common/piece.cpp b/common/piece.cpp
index ddba23f..2a11bd5 100644
--- a/common/piece.cpp
+++ b/common/piece.cpp
@@ -1762,29 +1762,55 @@ void Piece::AddConnections(CONNECTION_TYPE* pConnections)
void Piece::RemoveConnections(CONNECTION_TYPE* pConnections)
{
+ PtrArray<Piece> RebuildList;
int i, j;
for (i = 0; i < LC_CONNECTIONS; i++)
- for (j = 0; j < pConnections[i].numentries; j++)
- if (pConnections[i].entries[j].owner == this)
+ {
+ CONNECTION_TYPE* Type = &pConnections[i];
+
+ for (j = 0; j < Type->numentries; j++)
+ {
+ CONNECTION_ENTRY* Entry = &Type->entries[j];
+
+ if (Entry->owner == this)
{
- free(pConnections[i].entries[j].cons);
- pConnections[i].numentries--;
+ // Save a list of pieces that their lost connection to this one.
+ for (int k = 0; k < Entry->numcons; k++)
+ {
+ if (Entry->cons[k]->link != NULL)
+ {
+ if (RebuildList.FindIndex(Entry->cons[k]->link->owner) == -1)
+ RebuildList.Add(Entry->cons[k]->link->owner);
+ Entry->cons[k]->link->link = NULL;
+ }
+ }
+
+ free(Entry->cons);
+ Type->numentries--;
- for (; j < pConnections[i].numentries; j++)
- pConnections[i].entries[j] = pConnections[i].entries[j+1];
+ // Shrink array.
+ for (; j < Type->numentries; j++)
+ Type->entries[j] = Type->entries[j+1];
- if (pConnections[i].numentries % 5 == 0)
+ // Realloc to save memory.
+ if (Type->numentries % 5 == 0)
{
- if (pConnections[i].numentries > 0)
- pConnections[i].entries = (CONNECTION_ENTRY*)realloc(pConnections[i].entries, sizeof(CONNECTION_ENTRY)*pConnections[i].numentries);
+ if (Type->numentries > 0)
+ Type->entries = (CONNECTION_ENTRY*)realloc(Type->entries, sizeof(CONNECTION_ENTRY)*Type->numentries);
else
{
- free (pConnections[i].entries);
- pConnections[i].entries = NULL;
+ free(Type->entries);
+ Type->entries = NULL;
}
}
}
+ }
+ }
+
+ // Fix pieces that lost their connection to this one.
+ for (i = 0; i < RebuildList.GetSize(); i++)
+ RebuildList[i]->BuildDrawInfo();
}
/*