浏览代码

Merge pull request #183 from Unity-Technologies/fix_potential_crash

fix crash when font file doesn't exist
/main
GitHub 3 年前
当前提交
4339367c
共有 2 个文件被更改,包括 40 次插入5 次删除
  1. 15
      com.unity.uiwidgets/Runtime/engine/AndroidPlatformUtil.cs
  2. 30
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs

15
com.unity.uiwidgets/Runtime/engine/AndroidPlatformUtil.cs


internal delegate string UnpackFileCallback(string file);
internal static bool FileExists(string file)
{
var path = "jar:file://" + Application.dataPath + "!/assets/" + file;
using (var unpackerWWW = UnityWebRequest.Get(path)) {
unpackerWWW.SendWebRequest();
while (!unpackerWWW.isDone) {
} // This will block in the webplayer.
if (unpackerWWW.isNetworkError || unpackerWWW.isHttpError) {
return false;
}
}
return true;
}
[MonoPInvokeCallback(typeof(UnpackFileCallback))]
internal static string unpackFile(string file) {
var dir = Application.temporaryCachePath + "/";

30
com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Unity.UIWidgets.external.simplejson;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;

using UnityEngine.Profiling;
using UnityEngine.Scripting;
using UnityEngine.UI;
using Path = System.IO.Path;
using RawImage = UnityEngine.UI.RawImage;
namespace Unity.UIWidgets.engine {

foreach (var setting in settings) {
var font = new Dictionary<string, object>();
font.Add("family", value: setting.Key);
var dic = new Dictionary<string, object>[setting.Value.fonts.Length];
var dic = new List<Dictionary<string, object>>();
dic[j] = new Dictionary<string, object>();
var fontDic = new Dictionary<string, object>();
var fileExist = false;
dic[j].Add("asset", value: setting.Value.fonts[j].asset);
var assetPath = setting.Value.fonts[j].asset;
var assetAbsolutePath = Path.Combine(Application.streamingAssetsPath, assetPath);
#if !UNITY_EDITOR && UNITY_ANDROID
if (!AndroidPlatformUtil.FileExists(assetPath)) {
#else
if (!File.Exists(assetAbsolutePath)) {
#endif
Debug.LogError($"The font asset (family: \"{setting.Key}\", path: \"{assetPath}\") is not found");
}
else {
fileExist = true;
}
fontDic.Add("asset", value: setting.Value.fonts[j].asset);
dic[j].Add("weight", value: setting.Value.fonts[j].weight);
fontDic.Add("weight", value: setting.Value.fonts[j].weight);
}
if (fileExist) {
dic.Add(fontDic);
font.Add("fonts", value: dic);
font.Add("fonts", value: dic.ToArray());
result[i] = font;
i++;
}

正在加载...
取消
保存