Unity WebGL x iOS 15.4 解决方法

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值