Skip to content

Commit

Permalink
Fix Issue with 32-bit ARM
Browse files Browse the repository at this point in the history
Doing all intervals in microseconds means that long intervals (evening, morning) wind up being integer overflows. Which in Swift, look like crashes.
  • Loading branch information
Kaiede committed Aug 31, 2018
1 parent 6f867bf commit e403004
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/Core/Behavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public struct DefaultLightBehavior: Behavior {
let desiredChanges = (mergedSegment.totalBrightnessChange * targetChanges).rounded(.awayFromZero)
let desiredInterval = mergedSegment.duration / max(1.0, desiredChanges)
let interval = min(mergedSegment.duration, max(0.010, desiredInterval))
return .repeating(mergedSegment.startDate, .microseconds(Int(interval * 1_000_000.0)))
let finalInterval: DispatchTimeInterval = interval < 1000.0 ? .microseconds(Int(interval * 1_000_000.0)) : .milliseconds(Int(interval * 1_000.0))
return .repeating(mergedSegment.startDate, finalInterval)
}
}

0 comments on commit e403004

Please sign in to comment.