JTAppleCalendar icon indicating copy to clipboard operation
JTAppleCalendar copied to clipboard

JTACMonthLayout Crash

Open cesariel opened this issue 5 years ago • 8 comments

(Required) Version Number: 8.0.3

Description

#0 0x000000010483853c in JTACMonthLayout.setupDataFromDelegate() at ~/Pods/JTAppleCalendar/Sources/JTAppleCalendar/JTACMonthLayout.swift:168 JTAppleCalendar was compiled with optimization - stepping may behave oddly; variables may not be available.

Line 168: strictBoundaryRulesShouldApply = thereAreHeaders || delegate._cachedConfiguration.hasStrictBoundaries

Steps To Reproduce

func setupCalendarView() {
        calendarView.minimumLineSpacing = 0
        calendarView.minimumInteritemSpacing = 0        
        calendarView.visibleDates { (visibleDates) in
            self.setupViewsOfCalendar(from: visibleDates)
        }

        if(self.appoDates.count > 0) {
            self.calendarView.selectDates(self.appoDates)
        }
        self.formatter.dateFormat = "yyyy MM dd"
        self.calendarView.selectDates([formatter.date(from: getTodayDate())!])
    }
    
    func setupViewsOfCalendar(from visibleDates: DateSegmentInfo){    
        let date = visibleDates.monthDates.first!.date
        formatter.dateFormat = "yyyy"
        year.text = formatter.string(from: date)        
        formatter.dateFormat = "MMMM"
        month.text = formatter.string(from: date).capitalized
    }

Expected Behavior

Additional Context

cesariel avatar Feb 04 '20 17:02 cesariel

is it possible you can provide a sample app with this crash?

patchthecode avatar Feb 11 '20 11:02 patchthecode

I am also getting the same crash. Any luck with solving that @cesariel ?

umarchohan avatar Apr 01 '21 18:04 umarchohan

@umarchohan is it possible you can create a sample app (a barebones minimal app with no company code inside it) that recreates this issue?

patchthecode avatar Apr 01 '21 20:04 patchthecode

@patchthecode you can check with these settings as per @cesariel

func setupCalendarView() {
        calendarView.minimumLineSpacing = 0
        calendarView.minimumInteritemSpacing = 0        
        calendarView.visibleDates { (visibleDates) in
            self.setupViewsOfCalendar(from: visibleDates)
        }

        if(self.appoDates.count > 0) {
            self.calendarView.selectDates(self.appoDates)
        }
        self.formatter.dateFormat = "yyyy MM dd"
        self.calendarView.selectDates([formatter.date(from: getTodayDate())!])
    }
    
    func setupViewsOfCalendar(from visibleDates: DateSegmentInfo){    
        let date = visibleDates.monthDates.first!.date
        formatter.dateFormat = "yyyy"
        year.text = formatter.string(from: date)        
        formatter.dateFormat = "MMMM"
        month.text = formatter.string(from: date).capitalized
    }

umarchohan avatar Apr 01 '21 20:04 umarchohan

if you are using the same code. Can you confirm that it is not crashing at the forced optional values? I see you force the values here --> self.calendarView.selectDates([formatter.date(from: getTodayDate())!]) and here -> let date = visibleDates.monthDates.first!.date using the ! character.

patchthecode avatar Apr 02 '21 11:04 patchthecode

I'm encountering this same issue in version 8.0.3. The crash is caused by this implicitly unwrapped optional in JTACMonthView.swift:115:

// Configuration parameters from the dataSource
var _cachedConfiguration: ConfigurationParameters!

which is used in JTACMonthLayout.Swift:168:

strictBoundaryRulesShouldApply = thereAreHeaders || delegate._cachedConfiguration.hasStrictBoundaries

A nil value for _cachedConfiguration crashes the app. Since this is an internal property, I believe the library should be updated to avoid force unwrapping, and guard or handle nil values rather than crashing.

jvisenti avatar May 11 '21 10:05 jvisenti

this happened in production mode or in development? And how did it happen?

patchthecode avatar May 11 '21 11:05 patchthecode

this happened in production mode or in development? And how did it happen?

Production build. In my comment above I describe why the crash occurred, but since _cachedConfiguration is internal to JTAppleCalendar, I don't know what circumstances could cause it to be nil.

jvisenti avatar May 11 '21 11:05 jvisenti