When calling GetAllocatedSize() on a TBitArray it will round down the result of MaxBits / NumBitsPerDWORD. This means that not enough bytes are allocated when the MaxBits is not divisible by NumBitsPerDWORD(32).
1. Open UE4Editor (any project)
2. Create class based on Actor (MyActor)
3. In MyActor.h add the following:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = test) float MyNewNumber; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = test) float ArrayMax; TBitArray<> MyBit;
4. Add #include "Engine.h" to MyActor.cpp
5. In MyActor.cpp add the following:
a. BeginPlay:
MyBit.Init(false, ArrayMax);
MyNewNumber = MyBit.GetAllocatedSize();
b. Tick():
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(MyNewNumber));
6. Compile the MyActor class
7. Create a blueprint based on MyActor (MyActorBP)
8. Add instance of MyActorBP to the level
9. Set the value of ArrayMax to 600 in the details panel
10. Play in editor
Result:
72 will be printed out on screen (Number of bytes allocated for the bit array). An array of 600 bits would need 76 bytes (608bits)
Head over to the existing Questions & Answers thread and let us know what's up.
0 |
Component | UE - Foundation - Core |
---|---|
Affects Versions | 4.7.6 |
Target Fix | 4.9 |
Fix Commit | 2561443 |
---|
Created | May 20, 2015 |
---|---|
Resolved | May 21, 2015 |
Updated | Feb 5, 2017 |