Description

Error:  C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\Core\Public\Containers/SparseArray.h(778): error C2440: '-': cannot convert from 'const TSparseArrayElementOrFreeListLink<TAlignedBytes<4,4>> *' to 'const int *'
> C:\Program Files\Epic Games\UE_4.25\Engine\Source\Runtime\Core\Public\Containers/SparseArray.h(776): note: while compiling class template member function 'int32 TSparseArray<int,FDefaultSparseArrayAllocator>::PointerToIndex(const int *) const'

 

Note from user: 

we are using a workaround "int index = ptrToElement - &sparseArray[0];" but it is only valid code because in TSparseArray::operator[] a essential check has been commented out with the note "Disabled to improve loading times -BZ". The workaround would become a bug if that check would be enabled again.

The engine code line "int32 Index = Ptr - &GetData(0);" should be "int32 Index = Ptr - (ElementType*)&GetData(Index).ElementData;"

Steps to Reproduce
  1. Add the following code into a new class: TSparseArray<int> sparseArray;
    sparseArray.Add(1);
    int* ptrToElement = &sparseArray[0];
    int index = sparseArray.PointerToIndex(ptrToElement);
  2. Compile the project

 

Result: Compiler Error

 

Expected: No compiler error

 

 

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-93545 in the post.

1
Login to Vote

Fixed
ComponentUE - Foundation - Core
Affects Versions4.24.34.254.26
Target Fix4.26
Fix Commit13787026
Main Commit14207746
CreatedMay 26, 2020
ResolvedJun 29, 2020
UpdatedAug 28, 2020
View Jira Issue