Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't update Text via setState #749

Closed
harhoo opened this issue Apr 8, 2015 · 16 comments
Closed

Can't update Text via setState #749

harhoo opened this issue Apr 8, 2015 · 16 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@harhoo
Copy link

harhoo commented Apr 8, 2015

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.

@colinramsay
Copy link
Contributor

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>
        );
    }
});

@istarkov
Copy link
Contributor

istarkov commented Apr 8, 2015

+1
I have the same issue

@vjeux
Copy link
Contributor

vjeux commented Apr 8, 2015

Wow this is bad. @a2, @nicklockwood ?

@a2
Copy link
Contributor

a2 commented Apr 8, 2015

Ah, I know the problem. Will look in a couple hours.

@brentvatne
Copy link
Collaborator

I can confirm that I ran into the same issue with the newest version and I had to downgrade

@a2
Copy link
Contributor

a2 commented Apr 8, 2015

Yup. Mea culpa. Will fix shortly.

@brentvatne
Copy link
Collaborator

@a2 - thank you sir

@masterhou
Copy link

+1
I have the same issue
sliderios sample, i found drag the slider, will crash at RCTText setAttributedText [_textStorage setAttributedString:attributedText];

@a2 a2 self-assigned this Apr 9, 2015
@roman01la
Copy link

+1 Crashes anytime Text gets a value from component's state.

@eiriklv
Copy link

eiriklv commented Apr 9, 2015

+1 on this as well..

@a2
Copy link
Contributor

a2 commented Apr 9, 2015

A fix for this is landing internally and will be updated on GitHub at the next sync. Thanks for bringing this to my attention. 🍻

@SoulArsenic
Copy link

got that,thanks.

@manuelkiessling
Copy link

Had the very same issue at v0.3.8. At v0.3.10, it no longer occurs.

@a2
Copy link
Contributor

a2 commented Apr 10, 2015

Ah, looks like my fix landed in 0686b01. Feel free to reopen this issue (or create a new one) if a similar problem appears. Thanks!

@a2 a2 closed this as completed Apr 10, 2015
@roman01la
Copy link

@a2 0.3.10, works perfectly, thank you!

@manuelkiessling
Copy link

Thank you @harhoo for reporting, and @a2 for fixing it.

vjeux pushed a commit to vjeux/react-native that referenced this issue Apr 13, 2015
Summary: Fix `RCTText` crashes by wholly replacing the underlying `NSTextStorage`. This fixes GitHub issues facebook#748, facebook#749, and facebook#756.

Test Plan: There are a couple sample apps in facebook#749 that I used for testing this.
@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests