Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ISSUE-002

虚幻引擎字符串解码失败导致闪退

常见表现

系统语言为中文时,启动游戏立刻闪退。

相关源码

虚幻引擎 IOSPlatformMisc.cpp

typedef struct __Blob {
    uint32_t magic;
    uint32_t length;
    char data[];
} CS_GenericBlob;

extern NSString *EntitlementsData(void)
{
	//...
	
	CS_GenericBlob blob;
	Count = fread(&blob, sizeof(CS_GenericBlob), 1, file);
	
	if (__builtin_bswap32(blob.magic) == 0xfade7171)
	{
		uint32 blobLength = ntohl(blob.length);
		char data[blobLength];
		fread(&data[0], sizeof(char) * blobLength, 1, file);
		NSString *stringFromData = [NSString stringWithFormat: @"%s", data];
		NSLog(@"%@", stringFromData);
		fclose(file);
		return stringFromData;
	}
	
	//...
}

原因分析

data的长度应为blobLength减去8,而不是等于blobLength。由于fread()多读取了8个字节,最终调用[NSString stringWithFormat:]时字符串解码失败导致闪退。

解决方法

方法一:PlayCover Nightly版已修复此问题。

方法二:打开系统配置文件~/.CFUserTextEncoding,修改冒号前的部分为0x0,修改后重启电脑。