Crash (SECURE CRT) when trying to close a protobuf stream

Hello, my kings.

I have banged my head on a wall to get protobuf to work on unreal and finally managed to do it. It works wonders with windows fstream/ofstream, but when I try t

o use google::protobuf::io::FileOutputStream it crashes when I try to close it. It’s a really simple code:

int outfd = _wsopen(ss.str().c_str(), O_TRUNC, _S_IWRITE);
google::protobuf::io::FileOutputStream fout(outfd);

bool success;

success = google::protobuf::util::SerializeDelimitedToZeroCopyStream(GS, &fout);
if (!success) {
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT(“Failed to write”)));
}

fout.Close();

The error is:

Fatal error: [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/Launch/Private/Windows/LaunchWindows.cpp] [Line: 95] SECURE CRT: Invalid parameter detected. Expression: Unknown Function: Unknown. File: Unknown Line: 0

ucrtbase
ucrtbase
ucrtbase
libprotobuf
libprotobuf

Am I doing something wrong in the code or did I just probably configure my protobuf library incorrectly?

I love you.

That’s crashing probably well outside of Unreal, you’ll have to use the debugger and figure it out.