我使用的unity版本2021.3.24,下载AB时调用的UnityWebRequestAssetBundle.GetAssetBundle接口,webgl平台倒是能正常运行,但是微信开发者工具里会报错(大概率):exception thrown: RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds。改成UnityWebRequest请求url就能运行了,不知道小游戏文档里为啥没提这个问题: [图片] /// <summary> /// 安全的AssetBundle下载方法,兼容WebGL环境 /// </summary> /// <param name="url">AssetBundle URL</param> /// <param name="onComplete">完成回调</param> /// <param name="onError">错误回调</param> /// <returns></returns> public static IEnumerator DownloadAssetBundleSafe(string url, System.Action<AssetBundle> onComplete, System.Action<string> onError) { Debug.Log($"[WebGLFix] 开始安全下载AssetBundle: {url}"); UnityWebRequest request = null; #if UNITY_WEBGL && !UNITY_EDITOR // WebGL环境:使用字节流方式避免内存访问越界 request = new UnityWebRequest(url, "GET"); request.downloadHandler = new DownloadHandlerBuffer(); request.SetRequestHeader("Accept", "application/octet-stream"); // 设置请求头,确保正确的内容类型 Debug.Log("[WebGLFix] 使用WebGL兼容模式"); #else // 非WebGL环境:使用标准方式 request = UnityWebRequestAssetBundle.GetAssetBundle(url); Debug.Log("[WebGLFix] 使用标准模式"); #endif yield return request.SendWebRequest(); // 检查请求结果 #if UNITY_2020_1_OR_NEWER if (request.result != UnityWebRequest.Result.Success) #else if (request.isNetworkError || request.isHttpError) #endif { string error = $"下载失败: {request.error}, URL: {url}"; Debug.LogError($"[WebGLFix] {error}"); onError?.Invoke(error); yield break; } AssetBundle bundle = null; #if UNITY_WEBGL && !UNITY_EDITOR // WebGL环境:从字节数据创建AssetBundle if (request.downloadHandler?.data != null) { try { byte[] data = request.downloadHandler.data; Debug.Log($"[WebGLFix] 下载完成,数据大小: {data.Length} bytes"); // 使用LoadFromMemory创建AssetBundle,这比GetAssetBundle更安全 bundle = AssetBundle.LoadFromMemory(data); if (bundle == null) { Debug.LogError("[WebGLFix] LoadFromMemory返回null"); onError?.Invoke("无法从内存创建AssetBundle"); yield break; } } catch (System.Exception e) { Debug.LogError($"[WebGLFix] 从内存创建AssetBundle失败: {e.Message}\n{e.StackTrace}"); onError?.Invoke($"创建AssetBundle失败: {e.Message}"); yield break; } } else { Debug.LogError("[WebGLFix] 下载的数据为空"); onError?.Invoke("下载的数据为空"); yield break; } #else // 非WebGL环境:使用标准方式获取AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); #endif if (bundle == null) { Debug.LogError($"[WebGLFix] AssetBundle为null: {url}"); onError?.Invoke("AssetBundle为null"); yield break; } Debug.Log($"[WebGLFix] AssetBundle下载成功: {url}"); onComplete?.Invoke(bundle); request?.Dispose(); }
小游戏bundle下载后js堆内存溢出小游戏在后台空闲时会使用UnityWebRequestAssetBundle.GetAssetBundle(url, Hash128.Compute(url))接口下载bundle,下载完成后会ab.Unload(true)掉,并关闭这条链接www.Dispose(),通过Unity Profile分析Unity的堆内存没有变化,但发现JS的堆内存不断在增加,通过抓取几次堆内存比较发现,FSNode这个对象的实例一直增加没有被回收过,而FSNode好像又是保存bundle文件内容的,发现它一直存在在UnityCache中,不知道如何处理这个问题。 [图片] [图片]
09-05先试试文档里做法:[图片] 我是把微信开发者工具更新到稳定版就突然可以了,之前没注意安装的是开发版
unity转微信小程序报错,无法进入游戏unity转换完小程序之后,在开发者工具里无法进入游戏,报错 still waiting runDependencies, count= 1
09-04开发者工具里调用createVideo一直黑屏,确实按你说的把调试基础库换成3.2.5就正常播放了
wx.createVideo 在调试库3.2.5以下才有用 以上就没用console.log("create createVideo") let video = wx.createVideo({ x: 0, y: 0, width: 375, height: 667, src: 'https://mykx-cdn.dskystudio.com/CG.mp4', initialTime: 0, objectFit: 'cover', controls: true, autoplay: false, loop:false, showCenterPlayBtn: true, enableProgressGesture: true }); setTimeout(()=>{ video.play().then(res=>{ console.log('==========',res); }) },1000) 如题
02-08