From 527a297d6e2410277ff41c40dcbb56410d6a9118 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Wed, 13 Jun 2018 13:03:04 -0400 Subject: Handle missing json resource gracefully in 3dgm If the json resource is not found (it is not currently packaged with the APK), Viewer crashes. TBR= Change-Id: I0a0bdf7f97fdac8afc84d539c88d2a391e54855c Reviewed-on: https://skia-review.googlesource.com/134515 Reviewed-by: Florin Malita Commit-Queue: Florin Malita --- gm/3dgm.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gm') diff --git a/gm/3dgm.cpp b/gm/3dgm.cpp index 8014c246d3..a2818bba19 100644 --- a/gm/3dgm.cpp +++ b/gm/3dgm.cpp @@ -43,8 +43,9 @@ public: protected: void onOnceBeforeDraw() override { - auto stream = GetResourceAsStream("skotty/skotty_sample_2.json"); - fAnim = skottie::Animation::Make(stream.get()); + if (auto stream = GetResourceAsStream("skotty/skotty_sample_2.json")) { + fAnim = skottie::Animation::Make(stream.get()); + } int index = 0; for (float x = 0; x <= 1; ++x) { @@ -99,6 +100,9 @@ protected: } void onDraw(SkCanvas* canvas) override { + if (!fAnim) { + return; + } SkMatrix44 camera(SkMatrix44::kIdentity_Constructor), perspective(SkMatrix44::kIdentity_Constructor), mv(SkMatrix44::kIdentity_Constructor); -- cgit v1.2.3