Packaging fatal error when cooking

When i delete this line in Init func of logger.cpp in my library, I no longer get the error.

log_info((*this), "Log system is started %s/%s.", folder_name.c_str(), file_name.c_str());
  • log_info is a macro.

Then I checked what this macro does,

std::printf(format, args...);

if constexpr(LogType == ELogType::NORMAL || LogType == ELogType::FATAL)
{
	if (!is_initialized)
		Init("log", "LogSystem_NotInitialized");

	std::snprintf(log_buffer, log_buffer_size, format, args...);
	log_file << log_buffer;
	log_file.flush();

	if constexpr (LogType == ELogType::FATAL)
	{
		.....
	}
}

I deleted this std::printf line, and there is no error anymore. I think it is about std::print function. But when i try to use this function in another actor function , i get no error. It gives error only in Init funtion.

It can be related to that;

Paul.Tankard
Feb '17
For completeness sake I’ve found the actual cause of this, it’s trivial but was a pain to find.

As already mentioned, you can disable the CRT checks but you will lose the code that will check for any malformed strings. The real problem is caused by UE forcing stdout to UTF-8, when packaging, I’m not sure why this is needed.

When stdout is set to UTF-8, you can’t use printf or std::cout, it will fail this check _VALIDATE_STREAM_ANSI_RETURN.

The correct fix would be to replace printf / std::cout with wprintf / std::wcout, you can change any %s instanced in your printf calls to %hs to avoid having to change more code than needed. If it’s a third-party supplied dll/lib, it might be worth relaying the information.

After I test it one more time, I’ll reply if it is solved