Skip to content

Commit

Permalink
Fix crash when the initial window size is set to be smaller than minS…
Browse files Browse the repository at this point in the history
…ize; see 2ea2f6d

Ref: #2481
  • Loading branch information
lhc70000 committed Jun 2, 2019
1 parent 7975166 commit 0b0fcfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion iina/Extensions.swift
Expand Up @@ -95,6 +95,9 @@ extension NSSize {
``` ```
*/ */
func grow(toSize size: NSSize) -> NSSize { func grow(toSize size: NSSize) -> NSSize {
if width == 0 || height == 0 {
return size
}
let sizeAspect = size.aspect let sizeAspect = size.aspect
if aspect > sizeAspect { // self is wider, grow to meet height if aspect > sizeAspect { // self is wider, grow to meet height
return NSSize(width: size.height * aspect, height: size.height) return NSSize(width: size.height * aspect, height: size.height)
Expand All @@ -121,7 +124,10 @@ extension NSSize {
``` ```
*/ */
func shrink(toSize size: NSSize) -> NSSize { func shrink(toSize size: NSSize) -> NSSize {
let sizeAspect = size.aspect if width == 0 || height == 0 {
return size
}
let sizeAspect = size.aspect
if aspect < sizeAspect { // self is taller, shrink to meet height if aspect < sizeAspect { // self is taller, shrink to meet height
return NSSize(width: size.height * aspect, height: size.height) return NSSize(width: size.height * aspect, height: size.height)
} else { } else {
Expand Down
2 changes: 1 addition & 1 deletion iina/MainWindowController.swift
Expand Up @@ -2267,7 +2267,7 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
} }
// guard min size // guard min size
// must be slightly larger than the min size, or it will crash when the min size is auto saved as window frame size. // must be slightly larger than the min size, or it will crash when the min size is auto saved as window frame size.
videoSize = videoSize.satisfyMinSizeWithSameAspectRatio(minSize.add(1)) videoSize = videoSize.satisfyMinSizeWithSameAspectRatio(minSize)
// check if have geometry set // check if have geometry set
if let wfg = windowFrameFromGeometry(newSize: videoSize) { if let wfg = windowFrameFromGeometry(newSize: videoSize) {
rect = wfg rect = wfg
Expand Down

0 comments on commit 0b0fcfc

Please sign in to comment.