From 995cfe62ec19ab5f937e1b076cdd68305e7486d6 Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Wed, 27 Apr 2016 14:59:16 +0000 Subject: [PATCH] UPBGE: Fix python component initialization when object added. 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. --- .../gameengine/Converter/BL_BlenderDataConversion.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index aad97cab0f7d..880994724369 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -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(); } }