Skip to content
Permalink
Browse files

Fix crash when the initial window size is set to be smaller than minS…

…ize; see 2ea2f6d

Ref: #2481
  • Loading branch information...
lhc70000 committed Jun 2, 2019
1 parent 7975166 commit 0b0fcfc97dbf9d37600aa55933cf40e636f055b3
Showing with 8 additions and 2 deletions.
  1. +7 −1 iina/Extensions.swift
  2. +1 −1 iina/MainWindowController.swift
@@ -95,6 +95,9 @@ extension NSSize {
```
*/
func grow(toSize size: NSSize) -> NSSize {
if width == 0 || height == 0 {
return size
}
let sizeAspect = size.aspect
if aspect > sizeAspect { // self is wider, grow to meet height
return NSSize(width: size.height * aspect, height: size.height)
@@ -121,7 +124,10 @@ extension 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
return NSSize(width: size.height * aspect, height: size.height)
} else {
@@ -2267,7 +2267,7 @@ class MainWindowController: NSWindowController, NSWindowDelegate {
}
// 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.
videoSize = videoSize.satisfyMinSizeWithSameAspectRatio(minSize.add(1))
videoSize = videoSize.satisfyMinSizeWithSameAspectRatio(minSize)
// check if have geometry set
if let wfg = windowFrameFromGeometry(newSize: videoSize) {
rect = wfg

0 comments on commit 0b0fcfc

Please sign in to comment.
You can’t perform that action at this time.