Skip to content

Commit

Permalink
fix: hangs if resource files not found
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Dec 19, 2020
1 parent ef78637 commit a4186c2
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,27 @@ public sealed class LocalAssetManager : ResourceManager {
}

protected override bool ReadFile(string path, IntPtr dst) {
var localPath = CacheFileFromAsset(path);
var asset = File.ReadAllBytes(localPath);

using (var srcStr = new StdString(asset)) {
srcStr.Swap(new StdString(dst, false));
try {
Debug.Log(path);
var localPath = CacheFileFromAsset(path);
var asset = File.ReadAllBytes(localPath);

using (var srcStr = new StdString(asset)) {
srcStr.Swap(new StdString(dst, false));
}

return true;
} catch (Exception e) {
Debug.Log($"Failed to read file `{path}`: ${e.ToString()}");
return false;
}

return true;
}

private string GetAssetName(string assetPath) {
var assetName = Path.GetFileNameWithoutExtension(assetPath);
var extension = Path.GetExtension(assetPath);

return extension == ".tflite" ? $"{assetName}.bytes" : $"{assetName}.txt";
return (extension == ".tflite" || extension == ".bytes") ? $"{assetName}.bytes" : $"{assetName}.txt";
}

private string GetLocalFilePath(string assetName) {
Expand Down

0 comments on commit a4186c2

Please sign in to comment.