From dd5cde26aa39d794381710e253a3808a59314a9f Mon Sep 17 00:00:00 2001 From: Luigi Rosso <luigi.rosso@gmail.com> Date: Wed, 16 Dec 2020 14:36:44 -0800 Subject: [PATCH] Skip reading properties for null objects. --- lib/src/rive_file.dart | 10 +++++++--- lib/src/runtime_artboard.dart | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/src/rive_file.dart b/lib/src/rive_file.dart index 0f494f2..2d02fbf 100644 --- a/lib/src/rive_file.dart +++ b/lib/src/rive_file.dart @@ -153,8 +153,11 @@ class RiveFile { assert(!artboard.children.contains(artboard), 'artboard should never contain itself as a child'); - for (final object in artboard.objects) { - object?.onAdded(); + for (final object in artboard.objects.toList(growable:false)) { + if(object == null) { + continue; + } + object.onAdded(); } artboard.clean(); } @@ -165,7 +168,8 @@ class RiveFile { void _skipProperty(BinaryReader reader, int propertyKey, HashMap<int, CoreFieldType> propertyToField) { - var field = propertyToField[propertyKey]; + var field = + RiveCoreContext.coreType(propertyKey) ?? propertyToField[propertyKey]; if (field == null) { throw UnsupportedError('Unsupported property key $propertyKey. ' 'A new runtime is likely necessary to play this file.'); diff --git a/lib/src/runtime_artboard.dart b/lib/src/runtime_artboard.dart index 9e9b8cd..5430a97 100644 --- a/lib/src/runtime_artboard.dart +++ b/lib/src/runtime_artboard.dart @@ -18,8 +18,10 @@ class RuntimeArtboard extends Artboard implements CoreContext { @override T addObject<T extends Core>(T object) { - object.context = this; - object.id = _objects.length; + if (object != null) { + object.context = this; + object.id = _objects.length; + } _objects.add(object); return object; }