Description

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).

Steps to Reproduce

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)

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

0
Login to Vote

Fixed
ComponentUE - Foundation - Core
Affects Versions4.7.6
Target Fix4.9
Fix Commit2561443
CreatedMay 20, 2015
ResolvedMay 21, 2015
UpdatedFeb 5, 2017
View Jira Issue