Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit a4c30c3

Browse files
authored
Merge pull request #263 from Unity-Technologies/siyaoH/1.17/fixLottie
Fix Lottie crash during wrong path
2 parents 67a2551 + f856191 commit a4c30c3

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:65a6663fd0c92155fed6869a2902e486f27593d836c93a769ea137a0d4c068a5
3-
size 76739172
2+
oid sha256:6538e29dcefa8b013fd46288f17fbd95a14e6e2ae73ca15c67acc2ec25565e35
3+
size 76134220
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:d1de13043564e2f2b384ec3aefe1e500e42281b9d67cebca131c54ae841a0c37
3-
size 21804000
2+
oid sha256:99313d899e6946d4d614c2a0a5cacc050cc7ff0bd480c19428435363633169a8
3+
size 21801256
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:52dda23bf8cccf4e80dd4851bafe11bffae6beec925b1112ffa17cdbf13637e5
2+
oid sha256:74a8add2eb68589ffdde29bf411e53530415b618aaeee9a55fce80ad937aa4d9
33
size 11260928

com.unity.uiwidgets/Runtime/ui/painting.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3099,7 +3099,12 @@ public override int GetHashCode()
30993099

31003100
public class Skottie : NativeWrapper {
31013101
public Skottie(string path) {
3102-
_setPtr(Skottie_Construct(path));
3102+
var Id = Skottie_Construct(path);
3103+
if(Id == IntPtr.Zero){
3104+
Debug.Log($"cannot load lottie from {path}, please check file exist and valid");
3105+
}else {
3106+
_setPtr(Id);
3107+
}
31033108
}
31043109

31053110
public override void DisposePtr(IntPtr ptr) {

engine/src/lib/ui/painting/skottie.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ fml::RefPtr<Skottie> Skottie::Create(char* path) {
1414
path = (char*)fileOut;
1515
#endif
1616
sk_sp<skottie::Animation> animation_ = skottie::Animation::MakeFromFile(path);
17+
if(animation_ == nullptr){
18+
return nullptr;
19+
}
1720
return fml::MakeRefCounted<Skottie>(animation_);
1821
}
1922

@@ -32,19 +35,34 @@ float Skottie::duration() { return animation_->duration(); }
3235
UIWIDGETS_API(Skottie*)
3336
Skottie_Construct(char* path) {
3437
fml::RefPtr<Skottie> skottie = Skottie::Create(path);
38+
if(skottie.get() == nullptr){
39+
return nullptr;
40+
}
3541
skottie->AddRef();
3642
return skottie.get();
3743
}
3844

3945
UIWIDGETS_API(void)
40-
Skottie_Dispose(Skottie* ptr) { ptr->Release(); }
46+
Skottie_Dispose(Skottie* ptr) {
47+
if(ptr == nullptr){
48+
return;
49+
}
50+
ptr->Release();
51+
}
4152

4253
UIWIDGETS_API(void)
4354
Skottie_Paint(Skottie* ptr, Canvas* canvas, float x, float y, float width,
4455
float height, float frame) {
56+
if(ptr == nullptr){
57+
return;
58+
}
4559
ptr->paint(canvas, x, y, width, height, frame);
4660
}
4761

4862
UIWIDGETS_API(float)
49-
Skottie_Duration(Skottie* ptr) { return ptr->duration(); }
63+
Skottie_Duration(Skottie* ptr) {
64+
if(ptr == nullptr){
65+
return 0;
66+
}
67+
return ptr->duration(); }
5068
} // namespace uiwidgets

0 commit comments

Comments
 (0)