Unity WebGL x iOS 15.4 解决方法
碰到了苹果12打开报错的问题,找了个解决方案
找到 Unity 安装:
MacOS - Unity.app/Contents
Windows -\Editor\Data\
编辑:il2cpp/libil2cpp/metadata/GenericMetadata.cpp
找到该行:const Il2CppType* GenericMetadata::InflateIfNeeded
添加:#pragma clang optimize off到该函数之前的行以关闭该函数的编译器优化。
添加:#pragma clang optimize on在该函数结束后再次打开编译器优化。这将禁用该函数的编译器优化。
在您的 Unity 项目中,删除该目录Library/Bee/artifacts/WebGL/il2cpp以确保它拾取对该文件的更改。
另外,请转到“设置”/“Safari”并选择“清除历史记录和网站数据”,确保您的 iOS Safari 不会尝试加载缓存版本。
如果您使用的是Unity 2020,那么您需要删除缓存文件夹,可在此处找到:Library\Il2cppBuildCache
#pragma clang optimize off
const Il2CppType* GenericMetadata::InflateIfNeeded(const Il2CppType* type, const Il2CppGenericContext* context, bool inflateMethodVars)
{
switch (type->type)
{
case IL2CPP_TYPE_VAR:
return InflateGenericParameterIfNeeded(type, context->class_inst);
case IL2CPP_TYPE_MVAR:
{
if (context->method_inst)
return InflateGenericParameterIfNeeded(type, context->method_inst);
return type;
}
case IL2CPP_TYPE_ARRAY:
{
const Il2CppType* inflatedElementType = InflateIfNeeded(type->data.array->etype, context, inflateMethodVars);
if (!Il2CppTypeEqualityComparer::AreEqual(inflatedElementType, type->data.array->etype))
{
Il2CppType* inflatedType = (Il2CppType*)MetadataMalloc(sizeof(Il2CppType));
memcpy(inflatedType, type, sizeof(Il2CppType));
Il2CppArrayType* arrayType = (Il2CppArrayType*)MetadataMalloc(sizeof(Il2CppArrayType));
memcpy(arrayType, type->data.array, sizeof(Il2CppArrayType));
arrayType->etype = inflatedElementType;
inflatedType->data.array = arrayType;
++il2cpp_runtime_stats.inflated_type_count;
return inflatedType;
}
return type;
}
case IL2CPP_TYPE_PTR:
case IL2CPP_TYPE_SZARRAY:
{
const Il2CppType* inflatedElementType = InflateIfNeeded(type->data.type, context, inflateMethodVars);
if (!Il2CppTypeEqualityComparer::AreEqual(inflatedElementType, type->data.type))
{
Il2CppType* arrayType = (Il2CppType*)MetadataMalloc(sizeof(Il2CppType));
memcpy(arrayType, type, sizeof(Il2CppType));
arrayType->data.type = inflatedElementType;
++il2cpp_runtime_stats.inflated_type_count;
return arrayType;
}
return type;
}
case IL2CPP_TYPE_GENERICINST:
{
const Il2CppGenericInst* inst = type->data.generic_class->context.class_inst;
if (inst == NULL)
return NULL; // This is a generic type that was too deeply nested to generate
const Il2CppGenericInst* inflatedInst = GetInflatedGenericIntance(inst, context, inflateMethodVars);
Il2CppGenericClass* genericClass = GenericMetadata::GetGenericClass(GenericClass::GetTypeDefinition(type->data.generic_class), inflatedInst);
if (genericClass != type->data.generic_class)
{
Il2CppType* genericType = (Il2CppType*)MetadataMalloc(sizeof(Il2CppType));
memcpy(genericType, type, sizeof(Il2CppType));
genericType->data.generic_class = genericClass;
++il2cpp_runtime_stats.inflated_type_count;
return genericType;
}
return type;
}
default:
return type;
}
}
#pragma clang optimize on
参考链接
https://forum.unity.com/threads/ios-15-webgl-2-issue.1176116/page-2
https://forum.zap.works/t/unity-webgl-x-ios-15-4-workaround/8814