Summary
File.createViewModelInstance(.viewModelDefault(from: .artboardDefault(artboard))) skips all validation for the .viewModelDefault case and always returns a ViewModelInstance — even when no view model is linked to the artboard. The returned instance is invalid, but no Swift error is thrown. When this instance is subsequently bound via stateMachine.bindViewModelInstance(instance) (e.g. via Rive(dataBind: .instance(instance))), it produces continuous C++ errors:
Could not find a View Model linked to Artboard <ArtboardName>.
ERROR : State machine 0x1 not found for binding view model.
ERROR : State machine 0x1 not found for advance.
This affects any animation-only .riv file (no data binding configured) that is loaded via the async runtime.
Steps to Reproduce
- Have a
.riv file whose artboard has a state machine but no linked view model (pure animation, no data binding).
- In the async runtime, call:
let instance = try await file.createViewModelInstance(
.viewModelDefault(from: .artboardDefault(artboard))
)
- Pass
instance to Rive(dataBind: .instance(instance)).
- Observe
"Could not find a View Model linked to Artboard ..." warning and continuous "State machine 0x1 not found for advance" errors.
Expected Behavior
createViewModelInstance(.viewModelDefault) should throw FileError.invalidViewModel (or similar) when no view model is linked to the artboard, consistent with how .name(_, from: .name(_)) validates its inputs. Callers can then handle the error gracefully.
Alternatively, Rive(dataBind: .auto) — which uses try? — should be a safe fallback, but it is not: since createViewModelInstance never throws for .viewModelDefault, try? still returns a non-nil (invalid) instance and binds it, producing the same errors.
Actual Behavior
.viewModelDefault hits case .viewModelDefault: break — intentional skip of validation — and creates a ViewModelInstance backed by a C++ object that will fail silently when bound. No Swift error surfaces.
Suggested Fix
Add validation for the .viewModelDefault case: check whether the artboard has any linked view model before creating the instance, and throw if none is found. This would make the behavior consistent with other ViewModelInstanceSource cases and allow Rive(dataBind: .auto) to work correctly as a safe fallback.
Workaround
Call file.getViewModelNames() before createViewModelInstance and skip instance creation (use dataBind: .none) when the list is empty.
Environment
- rive-ios version: 6.19+
- Platform: iOS
Summary
File.createViewModelInstance(.viewModelDefault(from: .artboardDefault(artboard)))skips all validation for the.viewModelDefaultcase and always returns aViewModelInstance— even when no view model is linked to the artboard. The returned instance is invalid, but no Swift error is thrown. When this instance is subsequently bound viastateMachine.bindViewModelInstance(instance)(e.g. viaRive(dataBind: .instance(instance))), it produces continuous C++ errors:This affects any animation-only
.rivfile (no data binding configured) that is loaded via the async runtime.Steps to Reproduce
.rivfile whose artboard has a state machine but no linked view model (pure animation, no data binding).instancetoRive(dataBind: .instance(instance))."Could not find a View Model linked to Artboard ..."warning and continuous"State machine 0x1 not found for advance"errors.Expected Behavior
createViewModelInstance(.viewModelDefault)should throwFileError.invalidViewModel(or similar) when no view model is linked to the artboard, consistent with how.name(_, from: .name(_))validates its inputs. Callers can then handle the error gracefully.Alternatively,
Rive(dataBind: .auto)— which usestry?— should be a safe fallback, but it is not: sincecreateViewModelInstancenever throws for.viewModelDefault,try?still returns a non-nil (invalid) instance and binds it, producing the same errors.Actual Behavior
.viewModelDefaulthitscase .viewModelDefault: break— intentional skip of validation — and creates aViewModelInstancebacked by a C++ object that will fail silently when bound. No Swift error surfaces.Suggested Fix
Add validation for the
.viewModelDefaultcase: check whether the artboard has any linked view model before creating the instance, and throw if none is found. This would make the behavior consistent with otherViewModelInstanceSourcecases and allowRive(dataBind: .auto)to work correctly as a safe fallback.Workaround
Call
file.getViewModelNames()beforecreateViewModelInstanceand skip instance creation (usedataBind: .none) when the list is empty.Environment