UE4.25 Mac 字符转换 bug

在 4.26+ 中已修复。

Mac 用的是 2 字节的宽字符,但却按 4 字节的去转,当材质里参数有中文时,就会出现不一致的 bug:

Runtime/Core/Private/Serialization/MemoryImage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
FHashedName::FHashedName(const FName& InName)
{
if (!InName.IsNone())
{
const FNameEntry* Entry = InName.GetComparisonNameEntry();
const int32 InternalNumber = InName.GetNumber();
if (Entry->IsWide())
{
WIDECHAR WideNameBuffer[NAME_SIZE];
Entry->GetWideName(WideNameBuffer);
for (int32 i = 0; i < Entry->GetNameLength(); ++i)
{
WideNameBuffer[i] = FCharWide::ToUpper(WideNameBuffer[i]);
}
// Bug
// const FTCHARToUTF8 NameUTF8(WCHAR_TO_TCHAR(WideNameBuffer));
// Hash = CityHash64WithSeed(NameUTF8.Get(), NameUTF8.Length(), InternalNumber);

// WChar conversion bug in Mac
if (sizeof(WIDECHAR) != sizeof(TCHAR))
{
const FTCHARToUTF8 NameUTF8(WCHAR_TO_TCHAR(WideNameBuffer));
Hash = CityHash64WithSeed(NameUTF8.Get(), NameUTF8.Length(), InternalNumber);
}
else
{
const FTCHARToUTF8 NameUTF8((TCHAR*)WideNameBuffer);
Hash = CityHash64WithSeed(NameUTF8.Get(), NameUTF8.Length(), InternalNumber);
}
//
}
else
{
ANSICHAR AnsiNameBuffer[NAME_SIZE];
Entry->GetAnsiName(AnsiNameBuffer);
for (int32 i = 0; i < Entry->GetNameLength(); ++i)
{
AnsiNameBuffer[i] = FCharAnsi::ToUpper(AnsiNameBuffer[i]);
}
Hash = CityHash64WithSeed(AnsiNameBuffer, Entry->GetNameLength(), InternalNumber);
}
}
else
{
Hash = 0u;
}
}