fix: add nullptr check when retrieving text run on iOS at the artboard

Issue: https://github.com/rive-app/rive-ios/issues/286

Doing a small check on the artboard query for a text run for `nullptr` before returning from the Artboard

Diffs=
35daf194f fix: add nullptr check when retrieving text run on iOS at the artboard (#6312)

Co-authored-by: Zachary Plata <plata.zach@gmail.com>
This commit is contained in:
zplata
2023-12-06 14:38:49 +00:00
parent 27de5abf4b
commit a85c61b298
5 changed files with 21 additions and 4 deletions

View File

@@ -1 +1 @@
fabb7f97fe7b69368c9a7369febfecbc90be49cd
35daf194f427d04fb4a906f8162a1da53709aa5d

View File

@@ -1 +1 @@
7b7595392d849217e43a829b71dfad58ecf29b06
683bae68fa2a0cf8515f2dbfb35bdd0c3a298ecd

View File

@@ -24,7 +24,11 @@ struct TextInputView: DismissableView {
.padding()
.onChange(of: userInput, perform: { newValue in
if (!newValue.isEmpty) {
try! rvm.setTextRunValue("MyRun", textValue: userInput)
do {
try rvm.setTextRunValue("MyRun", textValue: userInput)
} catch {
debugPrint(error)
}
}
})
rvm.view()

View File

@@ -221,7 +221,11 @@ static int artInstanceCount = 0;
{
const std::string stdName = std::string([name UTF8String]);
auto riveTextRun = _artboardInstance->find<rive::TextValueRun>(stdName);
return [[RiveTextValueRun alloc] initWithTextValueRun:std::move(riveTextRun)];
if (riveTextRun != nullptr)
{
return [[RiveTextValueRun alloc] initWithTextValueRun:std::move(riveTextRun)];
}
return nullptr;
}
@end

View File

@@ -141,4 +141,13 @@
XCTAssertTrue([[textRun text] isEqualToString:@"Hello text"]);
}
- (void)testCatchingErrorOnBadTextRun
{
RiveFile* file = [Util loadTestFile:@"testtext" error:nil];
NSError* error = nil;
RiveArtboard* artboard = [file artboardFromName:@"New Artboard" error:&error];
RiveTextValueRun* textRun = [artboard textRun:@"BADRUN"];
XCTAssertNil(textRun);
}
@end