I’m using FJsonObjectConverter::JsonObjectStringToUStruct to parse a json FString to a UStruct, I call this function in a thread when I receive data from a network udp socket.
This has been working fine until 4.22.x, but on 4.23.x seems to not be working at all and as an effect it crashes unreal after 2-3 seconds.
The code segment:
...
while (true) {
if (Socket->RecvFrom(data, sizeof(data), bytes_read, *addr_in)) {
SomeUStructType myObject;
FString json = BytesToStringFixed(data, static_cast<int32_t>(bytes_read)); // This indeed contains a valid json when logged
if (json.EndsWith("}")) {
FJsonObjectConverter::JsonObjectStringToUStruct(json, &myObject, 0, 0); // this line seems to crash on 4.23.0
}
}
}
...
The error message when unreal crashes:
Unhandled exception
UE4Editor_JsonUtilities!__chkstk() [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\misc\amd64\chkstk.asm:109]
UE4Editor_JsonUtilities!`anonymous namespace'::JsonValueToUPropertyWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:710]
UE4Editor_JsonUtilities!`anonymous namespace'::JsonAttributesToUStructWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:805]
UE4Editor_JsonUtilities!`anonymous namespace'::ConvertScalarJsonValueToUPropertyWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:581]
UE4Editor_JsonUtilities!`anonymous namespace'::JsonValueToUPropertyWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:760]
UE4Editor_JsonUtilities!`anonymous namespace'::JsonAttributesToUStructWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:805]
UE4Editor_JsonUtilities!`anonymous namespace'::ConvertScalarJsonValueToUPropertyWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:581]
UE4Editor_JsonUtilities!`anonymous namespace'::JsonValueToUPropertyWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:760]
UE4Editor_JsonUtilities!`anonymous namespace'::ConvertScalarJsonValueToUPropertyWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:458]
UE4Editor_JsonUtilities!`anonymous namespace'::JsonValueToUPropertyWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:760]
UE4Editor_JsonUtilities!`anonymous namespace'::JsonAttributesToUStructWithContainer() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:805]
UE4Editor_JsonUtilities!FJsonObjectConverter::JsonObjectToUStruct() [d:\build\++ue4\sync\engine\source\runtime\jsonutilities\private\jsonobjectconverter.cpp:832]
UE4Editor_Smartsuit!FJsonObjectConverter::JsonObjectStringToUStruct<FVirtualProductionFrame>() [c:\program files\epic games\ue_4.23\engine\source\runtime\jsonutilities\public\jsonobjectconverter.h:236]
UE4Editor_Smartsuit!VPStreamingNetwork::Run() [c:\git\ue4\ue423\plugins\smartsuit\source\smartsuit\private\myclass.cpp:125]
UE4Editor_Core!FRunnableThreadWin::Run() [d:\build\++ue4\sync\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:96]
Here’s the BytesToStringFixed function
FString BytesToStringFixed(const uint8 *In, int32 Count)
{
FString Broken = BytesToString(In, Count);
FString Fixed;
for (int i = 0; i < Broken.Len(); i++)
{
const TCHAR c = Broken[i] - 1;
Fixed.AppendChar(c);
}
return Fixed;
}
Edit:
Seems the crash happens when there are objects in the arrays of the parent ustruct. So having the following structs
USTRUCT(BlueprintType)
struct FSomeUStructType {
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Category", meta = (ToolTip = "Tooltip."))
int version;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Category", meta = (ToolTip = "Tooltip."))
TArray<FOtherUStructType> children;
}
USTRUCT(BlueprintType)
struct FOtherUStructType {
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Category")
FString name;
}
These works:
“{"version":4,"children":}”
“{"version":4,"children":[{}]}”
“{"version":4,"children":[{"notexistingkey": "somevalue"}]}”
While this is not working:
“{"version":4,"children":[{"name":"childname"}]}”
If anyone has any insights It’ll be appreciated. If you need more information please let me know.