Crash in version 1.26 with textLineHeight = .relativeToFont

2
closed
dtamiazzo
dtamiazzo
Posted 3 months ago

Crash in version 1.26 with textLineHeight = .relativeToFont #482

Description

Hi all, we're experiencing a crash with the new version of the library (1.26.0) with the SkeletonAppearance with textLineHeight = .relativeToFont. The app crashes with "NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds" when calling layoutSkeletonIfNeeded if the UILabel to Skeletonize has nil text or is empty.

What type of issue is this? (place an x in one of the [ ])

  • [x ] bug
  • enhancement (feature request)
  • question
  • documentation related
  • discussion

Requirements (place an x in each of the [ ])

  • [ x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [ x] I've read and agree to the Code of Conduct.
  • [ x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

SkeletonView Environment:

**SkeletonView version: 1.26.0 **Xcode version: 13.2.1 **Swift version: Swift 5.5.2

Steps to reproduce:

Please replace this with the steps to reproduce the behavior.

  1. create a label = UILabel() with label.text = nil and set label.isSkeletonable = true
  2. set SkeletonAppearance.default.textLineHeight = .relativeToFont
  3. call showSkeleton() on the label
  4. the app crashes on the line 94 of SkeletonTextNode.swift: if let attributes = attributedText?.attributes(at: 0, effectiveRange: nil)

Expected result:

The app shouldn't crash.

Actual result:

The app crashes with "NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds"

Attachments:

I suggest this edit at line 93 of SkeletonTextNode.swift:

var fontLineHeight: CGFloat? {
    if let attributedText = attributedText,
       attributedText.string.count > 0,
       let fontAttribute = attributedText.attributes(at: 0, effectiveRange: nil).first(where: { $0.key == .font }) {
        return fontAttribute.value as? CGFloat ?? font.lineHeight
    } else {
        return font.lineHeight
    }
}
Juanpe
Juanpe
Created 3 months ago

Hi @dtamiazzo 👋🏼 Thanks for reporting this issue.

Good catch! I'll fix it asap 👍🏼

Juanpe
Juanpe
Created 3 months ago

This fix was fixed in the version 1.29.2. Thanks for reporting 👍🏼