Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error while enter text in textfield like: _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index 7

Application crash when enter text in uitextfiled and getting error like: _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index 7. Any help would be much appreciated..

like image 463
Sachin Kumaram Avatar asked Nov 10 '22 10:11

Sachin Kumaram


1 Answers

The __NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index stuff does (to the best of my knowledge) not cause the crash.

But there seems to be an underlying cause for both the crash and the invalid glyph. These kinds of errors pop up in places like custom NSTextStorage subclasses's -processEditing, when your perform changes to the text storage while layout is in progress and/or vice versa.

How to Find Bugs in General & in TextKit Components Specifically

Since the OP didn't offer more details, here's a suggested list to find instead of solving the problem. After every step, try to run the program and look for crashes:

  1. Remove any TextKit related custom subclasses and delegates (!) from the component, including UITextField subclasses themselves, and use system default components instead. This should not crash anymore.
  2. Try to put the delegates back into place, if there were any. I'm thinking about NSTextStorageDelegate and friends.
  3. If nothing crashes, deactivate the delegates again. (If it does, you know whose fault it is now :))

Now on to component subclasses; put the subclasses back into operation in this order, derived from the chain of responsibility in the layout process, one by one:

  1. Add back custom NSGlyphGenerator subclasses, if any. They are way down the command chain. If nothing happens, use the system default again for now.
  2. Do the same for NSTypesetter subclasses, put it in, then toggle it off again.
  3. Same for NSLayoutManager subclasses, if any. This stuff is still further down the command chain.
  4. Add back custom NSTextStorage subclass. Text storages are high up the command chain and may have multiple places where they can break.

Then try combinations, starting at the bottom again, and try as many combos as you need until the app breaks.

Once you find the exact call that causes the crash, open a new question :)

like image 143
ctietze Avatar answered Nov 15 '22 05:11

ctietze