Can't update Text via setState
If I try and update the value of Text via setState (which I am assuming should be possible), XCode crashes, with the following stack trace:
2015-04-08 13:17:00.675 SampleApp[3432:124680] !!! _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index 7 2015-04-08 13:17:00.716 SampleApp[3432:124680] * Terminating app due to uncaught exception 'NSRangeException', reason: '* NSRunStorage, _NSBlockNumberForIndex(): index (7) beyond array bounds (0)' *** First throw call stack: ( 0 CoreFoundation 0x0000000107de8a75 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000107262bb7 objc_exception_throw + 45 2 CoreFoundation 0x0000000107de89ad +[NSException raise:format:] + 205 3 UIFoundation 0x000000010fce2c8f _NSBlockNumberForIndex + 84 4 UIFoundation 0x000000010fca1e27 -[NSLayoutManager(NSPrivate) _invalidateGlyphsForExtendedCharacterRange:changeInLength:includeBlocks:] + 786 5 UIFoundation 0x000000010fccf692 -[NSLayoutManager _invalidateGlyphsForCharacterRange:editedCharacterRange:changeInLength:actualCharacterRange:] + 176 6 UIFoundation 0x000000010fcd1934 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 208 7 UIFoundation 0x000000010fcf80ba -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 152 8 UIFoundation 0x000000010fcf7bf2 -[NSTextStorage processEditing] + 367 9 UIFoundation 0x000000010fcf7a4c -[NSTextStorage edited:range:changeInLength:] + 305 10 Foundation 0x0000000106e0c2f8 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 330 11 UIFoundation 0x000000010fcf9919 -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 78 12 SampleApp 0x000000010696ca3a -[RCTText setAttributedText:] + 106 13 SampleApp 0x000000010696bd09 __55-[RCTTextManager uiBlockToAmendWithShadowViewRegistry:]_block_invoke_2 + 201 14 SampleApp 0x0000000106908683 __45-[RCTSparseArray enumerateObjectsUsingBlock:]_block_invoke + 147 15 CoreFoundation 0x0000000107d29ec6 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102 16 CoreFoundation 0x0000000107d29dcc -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 204 17 SampleApp 0x00000001069085af -[RCTSparseArray enumerateObjectsUsingBlock:] + 415 18 SampleApp 0x000000010696bbf0 __55-[RCTTextManager uiBlockToAmendWithShadowViewRegistry:]_block_invoke + 208 19 SampleApp 0x000000010696bfeb __55-[RCTTextManager uiBlockToAmendWithShadowViewRegistry:]_block_invoke137 + 443 20 SampleApp 0x0000000106935c6c __27-[RCTUIManager addUIBlock:]_block_invoke + 124 21 SampleApp 0x000000010693ebb6 __29-[RCTUIManager flushUIBlocks]_block_invoke + 342 22 libdispatch.dylib 0x000000010acd3186 _dispatch_call_block_and_release + 12 23 libdispatch.dylib 0x000000010acf2614 _dispatch_client_callout + 8 24 libdispatch.dylib 0x000000010acdaa1c _dispatch_main_queue_callback_4CF + 1664 25 CoreFoundation 0x0000000107d50749 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 26 CoreFoundation 0x0000000107d1362b __CFRunLoopRun + 2043 27 CoreFoundation 0x0000000107d12bc6 CFRunLoopRunSpecific + 470 28 GraphicsServices 0x000000010b75aa58 GSEventRunModal + 161 29 UIKit 0x0000000109812580 UIApplicationMain + 1282 30 SampleApp 0x00000001068af033 main + 115 31 libdyld.dylib 0x000000010ad27145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
This happens in even the simplest of apps, e.g.
var SampleApp = React.createClass({
getInitialState() {
return {
score: 0
}
},
render() {
return (
<View style={styles.container}>
<Text style={styles.label}>{'Score: ' + this.state.score}</Text>
<TouchableHighlight
activeOpacity={0.6}
underlayColor={'white'}
onPress={() => this.setState({score: ++this.state.score})}>
<Text style={styles.button}>Tap</Text>
</TouchableHighlight>
</View>
);
}
});
Any ideas?
Running OSX 10.9.5 and XCode 6.2.
I generated a new app which is running 0.3.7 and I see this too. This works:
var issue749 = React.createClass({
getInitialState() {
return {
score: 0
}
},
componentDidMount() {
this.setState({
score: 6
})
},
render() {
return (
<View>
<Text style={styles.label}>{this.state.score}</Text>
</View>
);
}
});
However this doesn't - it causes a crash:
var issue749 = React.createClass({
getInitialState() {
return {
score: 0
}
},
componentDidMount() {
setInterval(() => {
this.setState({
score: 6
});
}, 500);
},
render() {
return (
<View>
<Text style={styles.label}>{this.state.score}</Text>
</View>
);
}
});
+1 I have the same issue
Wow this is bad. @a2, @nicklockwood ?
Ah, I know the problem. Will look in a couple hours.
I can confirm that I ran into the same issue with the newest version and I had to downgrade
Yup. Mea culpa. Will fix shortly.
@a2 - thank you sir
+1 I have the same issue sliderios sample, i found drag the slider, will crash at RCTText setAttributedText [_textStorage setAttributedString:attributedText];
+1 Crashes anytime Text gets a value from component's state.
+1 on this as well..
A fix for this is landing internally and will be updated on GitHub at the next sync. Thanks for bringing this to my attention. :beers:
got that,thanks.
Had the very same issue at v0.3.8. At v0.3.10, it no longer occurs.
Ah, looks like my fix landed in 0686b0147c8c8084e4a226b7ea04585362eccea8. Feel free to reopen this issue (or create a new one) if a similar problem appears. Thanks!
@a2 0.3.10, works perfectly, thank you!
Thank you @harhoo for reporting, and @a2 for fixing it.