JRE-471 Crash on macOS Sierra after Sleep

Replaced [NSScreen screens] 'objectAtIndex' with 'firstObject' to get nil instead of NSRangeException. Added nil checks

(cherry picked from commit d6b98511262055c01522d9ec8024253af7e91564)
(cherry picked from commit cef970e1ba)
This commit is contained in:
Alexey Ushakov
2017-10-13 17:16:25 +03:00
committed by Vitaly Provodin
parent 280b1ae0e1
commit 283587c032
4 changed files with 42 additions and 18 deletions

View File

@@ -790,9 +790,11 @@ static BOOL shouldUsePressAndHold() {
CDragSource *dragSource = self._dragSource;
NSDragOperation dragOp = NSDragOperationNone;
if (dragSource != nil) {
if (dragSource != nil)
dragOp = [dragSource draggingSourceOperationMaskForLocal:flag];
}
else if ([super respondsToSelector:@selector(draggingSourceOperationMaskForLocal:)])
dragOp = [super draggingSourceOperationMaskForLocal:flag];
return dragOp;
}
@@ -802,9 +804,11 @@ static BOOL shouldUsePressAndHold() {
CDragSource *dragSource = self._dragSource;
NSArray* array = nil;
if (dragSource != nil) {
if (dragSource != nil)
array = [dragSource namesOfPromisedFilesDroppedAtDestination:dropDestination];
}
else if ([super respondsToSelector:@selector(namesOfPromisedFilesDroppedAtDestination:)])
array = [super namesOfPromisedFilesDroppedAtDestination:dropDestination];
return array;
}
@@ -844,9 +848,11 @@ static BOOL shouldUsePressAndHold() {
CDragSource *dragSource = self._dragSource;
BOOL result = FALSE;
if (dragSource != nil) {
if (dragSource != nil)
result = [dragSource ignoreModifierKeysWhileDragging];
}
else if ([super respondsToSelector:@selector(ignoreModifierKeysWhileDragging)])
result = [super ignoreModifierKeysWhileDragging];
return result;
}
@@ -860,9 +866,11 @@ static BOOL shouldUsePressAndHold() {
CDropTarget *dropTarget = self._dropTarget;
NSDragOperation dragOp = NSDragOperationNone;
if (dropTarget != nil) {
if (dropTarget != nil)
dragOp = [dropTarget draggingEntered:sender];
}
else if ([super respondsToSelector:@selector(draggingEntered:)])
dragOp = [super draggingEntered:sender];
return dragOp;
}
@@ -872,9 +880,11 @@ static BOOL shouldUsePressAndHold() {
CDropTarget *dropTarget = self._dropTarget;
NSDragOperation dragOp = NSDragOperationNone;
if (dropTarget != nil) {
if (dropTarget != nil)
dragOp = [dropTarget draggingUpdated:sender];
}
else if ([super respondsToSelector:@selector(draggingUpdated:)])
dragOp = [super draggingUpdated:sender];
return dragOp;
}
@@ -894,9 +904,11 @@ static BOOL shouldUsePressAndHold() {
CDropTarget *dropTarget = self._dropTarget;
BOOL result = FALSE;
if (dropTarget != nil) {
if (dropTarget != nil)
result = [dropTarget prepareForDragOperation:sender];
}
else if ([super respondsToSelector:@selector(prepareForDragOperation:)])
result = [super prepareForDragOperation:sender];
return result;
}
@@ -906,9 +918,11 @@ static BOOL shouldUsePressAndHold() {
CDropTarget *dropTarget = self._dropTarget;
BOOL result = FALSE;
if (dropTarget != nil) {
if (dropTarget != nil)
result = [dropTarget performDragOperation:sender];
}
else if ([super respondsToSelector:@selector(performDragOperation:)])
result = [super performDragOperation:sender];
return result;
}

View File

@@ -744,8 +744,14 @@ JNI_COCOA_EXIT(env);
// Also see +[CWindow convertAWTToCocoaScreenRect]
// NSScreen-to-JavaScreen mapping:
- (NSPoint) mapNSScreenPointToJavaWithOffset:(NSPoint)screenPoint {
NSRect mainR = [[[NSScreen screens] objectAtIndex:0] frame];
NSPoint point = NSMakePoint(screenPoint.x, mainR.size.height - (screenPoint.y));
NSScreen *primaryScreen = [[NSScreen screens] firstObject];
NSPoint point = NSMakePoint(0, 0);
if (primaryScreen == nil) {
return point;
}
NSRect mainR = [primaryScreen frame];
point = NSMakePoint(screenPoint.x, mainR.size.height - (screenPoint.y));
// Adjust the point with the drag image offset to get the real mouse hotspot:
// The point should remain in screen coordinates (as per DragSourceEvent.getLocation() documentation)

View File

@@ -97,7 +97,7 @@ NSSize JavaToNSSize(JNIEnv *env, jobject dimension) {
}
static NSScreen *primaryScreen(JNIEnv *env) {
NSScreen *primaryScreen = [[NSScreen screens] objectAtIndex:0];
NSScreen *primaryScreen = [[NSScreen screens] firstObject];
if (primaryScreen != nil) return primaryScreen;
if ((env != NULL) && ([NSThread isMainThread] == NO)) {
JNU_ThrowByName(env, "java/lang/RuntimeException", "Failed to convert, no screen.");

View File

@@ -53,11 +53,15 @@ NSString* findScaledImageName(NSString *fileName,
static NSScreen* SplashNSScreen()
{
return [[NSScreen screens] objectAtIndex: 0];
return [[NSScreen screens] firstObject];
}
static void SplashCenter(Splash * splash)
{
NSScreen *primaryScreen = SplashNSScreen();
if (primaryScreen == nil) return;
NSRect screenFrame = [SplashNSScreen() frame];
splash->x = (screenFrame.size.width - splash->width) / 2;