From 5e0a5049d873b5896553ee530562c28ffd3fbe0c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 9 May 2013 02:57:09 +0200 Subject: Fix NEWT MultiMonitor Regression: Use case w/o attached monitor, and NPE (Cache) in ScreenImpl.getVirtualMonitorDevice(..). W/ RandR13, we can have a case of an Output/CRT w/o valid modes, indicating a switched off or detached monitor. ScreenImpl.getVirtualMonitorDevice(..) requires a Cache .. due to MonitorModeProps.streamInMonitorDevice(..) --- src/newt/classes/jogamp/newt/ScreenImpl.java | 29 ++++++++++++++++------ .../jogamp/newt/driver/x11/ScreenDriver.java | 4 ++- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'src/newt') diff --git a/src/newt/classes/jogamp/newt/ScreenImpl.java b/src/newt/classes/jogamp/newt/ScreenImpl.java index d7bd326fe..7edf7b63a 100644 --- a/src/newt/classes/jogamp/newt/ScreenImpl.java +++ b/src/newt/classes/jogamp/newt/ScreenImpl.java @@ -446,7 +446,13 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { refMonitorModeListener.remove(sml); } - private final MonitorMode getVirtualMonitorMode(int modeId) { + /** + * + * @param cache optional .. + * @param modeId + * @return + */ + private final MonitorMode getVirtualMonitorMode(MonitorModeProps.Cache cache, int modeId) { final int[] props = new int[MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL]; int i = 0; props[i++] = MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL; @@ -460,10 +466,17 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { if( MonitorModeProps.NUM_MONITOR_MODE_PROPERTIES_ALL != i ) { throw new InternalError("XX"); } - return MonitorModeProps.streamInMonitorMode(null, null, props, 0); + return MonitorModeProps.streamInMonitorMode(null, cache, props, 0); } - - private final MonitorDevice getVirtualMonitorDevice(int monitorId, MonitorMode currentMode) { + + /** + * + * @param cache mandatory ! + * @param monitorId + * @param currentMode + * @return + */ + private final MonitorDevice getVirtualMonitorDevice(MonitorModeProps.Cache cache, int monitorId, MonitorMode currentMode) { int[] props = new int[MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES]; int i = 0; props[i++] = MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES; @@ -480,7 +493,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { if( MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES != i ) { throw new InternalError("XX"); } - return MonitorModeProps.streamInMonitorDevice(null, null, this, props, 0); + return MonitorModeProps.streamInMonitorDevice(null, cache, this, props, 0); } /** @@ -498,7 +511,7 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { if( 0>=getWidth() || 0>=getHeight() ) { updateVirtualScreenOriginAndSize(); } - res = getVirtualMonitorMode(monitor.getCurrentMode().getId()); + res = getVirtualMonitorMode(null, monitor.getCurrentMode().getId()); } return res; } @@ -522,9 +535,9 @@ public abstract class ScreenImpl extends Screen implements MonitorModeListener { if( 0 >= collectNativeMonitorModes(cache) ) { updateVirtualScreenOriginAndSize(); vScrnSizeUpdated = true; - final MonitorMode mode = getVirtualMonitorMode(0); + final MonitorMode mode = getVirtualMonitorMode(cache, 0); cache.monitorModes.getOrAdd(mode); - final MonitorDevice monitor = getVirtualMonitorDevice(0, mode); + final MonitorDevice monitor = getVirtualMonitorDevice(cache, 0, mode); cache.monitorDevices.getOrAdd(monitor); } if(DEBUG) { diff --git a/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java index f2836f190..b8b13939b 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java +++ b/src/newt/classes/jogamp/newt/driver/x11/ScreenDriver.java @@ -139,7 +139,9 @@ public class ScreenDriver extends ScreenImpl { if( cache.monitorModes.size() > 0 ) { for(int i = 0; i < crtCount; i++) { final int[] monitorProps = rAndR.getMonitorDeviceProps(device.getHandle(), this, cache, i); - if( null != monitorProps ) { // enabled + if( null != monitorProps && + MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES <= monitorProps[0] && // Enabled ? I.e. contains active modes ? + MonitorModeProps.MIN_MONITOR_DEVICE_PROPERTIES <= monitorProps.length ) { MonitorModeProps.streamInMonitorDevice(null, cache, this, monitorProps, 0); } } -- cgit v1.2.3