Skip to content

Can't update Text via setState  #749

@harhoo

Description

@harhoo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions