Fix access violation crash in GarbageCollection.cpp - ProcessObjectArray.

[CL 2666992 by David Ratti in Main branch]
This commit is contained in:
David Ratti
2015-08-24 19:32:08 -04:00
committed by David.Ratti@epicgames.com
parent f30e3d0c0e
commit 2daef398e4

View File

@@ -795,7 +795,11 @@ public:
#endif
CurrentObject = ObjectsToSerialize[CurrentIndex++];
const UObject * const NextObject = ObjectsToSerialize.GetData()[CurrentIndex]; // special syntax avoiding out of bounds checking
// GetData() used to avoiding bounds checking (min and max)
// FMath::Min used to avoid out of bounds (without branching) on last iteration. Though anything can be passed into PrefetchBlock,
// reading ObjectsToSerialize out of bounds is not safe since ObjectsToSerialize[Num()] may be an unallocated/unsafe address.
const UObject * const NextObject = ObjectsToSerialize.GetData()[FMath::Min<int32>(CurrentIndex, ObjectsToSerialize.Num() - 1)];
// Prefetch the next object assuming that the property size of the next object is the same as the current one.
// This allows us to avoid a branch here.
FPlatformMisc::PrefetchBlock(NextObject, CurrentObject->GetClass()->GetPropertiesSize());