Skip to content

Commit

Permalink
UPBGE: Fix python component initialization when object added.
Browse files Browse the repository at this point in the history
Previously we was used iterator to loop on all object but the list can
be reallocated if enough objects are added which cause that the iterator
become invalid.

To fix it we simply use indexes instead.
  • Loading branch information
panzergame committed Apr 27, 2016
1 parent 4015384 commit 995cfe6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions source/gameengine/Converter/BL_BlenderDataConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2242,10 +2242,12 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
}
}

/* Initialize python components, use a fixed end iterator because some component can add object
* and these objects are only at the end of the list. */
for (CListValue::iterator it = objectlist->GetBegin(), end = objectlist->GetEnd(); it != end; ++it) {
KX_GameObject *gameobj = (KX_GameObject *)*it;
/* Initialize python components, use a fixed size because some component can add object
* and these objects are only at the end of the list. Never use iterato here because the
* begining iterator can be changed and then pointed to a fake game object.
*/
for (unsigned int i = 0, size = objectlist->GetCount(); i < size; ++i) {
KX_GameObject *gameobj = (KX_GameObject *)objectlist->GetValue(i);
gameobj->InitComponents();
}
}
Expand Down

0 comments on commit 995cfe6

Please sign in to comment.