Skip to content

Commit 3122344

Browse files
HeikoKlarefedejeanne
authored andcommitted
[Win32] Avoid NPE when autoscaling is disabled on shell
When autoscaling is disabled for a shell, setLocation(), setBounds() and setSize() can throw an NPE as they want to access the parent's zoom even though there is no parent. This fixes the behavior by adding an according null check.
1 parent f0a9f93 commit 3122344

File tree

1 file changed

+3
-3
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+3
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,7 +3298,7 @@ void setBoundsInPixels (int x, int y, int width, int height, int flags, boolean
32983298
public void setBounds (Rectangle rect) {
32993299
checkWidget ();
33003300
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
3301-
int zoom = autoScaleDisabled ? parent.getZoom() : getZoom();
3301+
int zoom = autoScaleDisabled && parent != null ? parent.getZoom() : getZoom();
33023302
setBoundsInPixels(Win32DPIUtils.pointToPixel(rect, zoom));
33033303
}
33043304

@@ -3556,7 +3556,7 @@ public void setLayoutData (Object layoutData) {
35563556
*/
35573557
public void setLocation (int x, int y) {
35583558
checkWidget ();
3559-
int zoom = autoScaleDisabled ? parent.getZoom() : getZoom();
3559+
int zoom = autoScaleDisabled && parent != null ? parent.getZoom() : getZoom();
35603560
x = DPIUtil.pointToPixel(x, zoom);
35613561
y = DPIUtil.pointToPixel(y, zoom);
35623562
setLocationInPixels(x, y);
@@ -3813,7 +3813,7 @@ public void setRegion (Region region) {
38133813
*/
38143814
public void setSize (int width, int height) {
38153815
checkWidget ();
3816-
int zoom = autoScaleDisabled ? parent.getZoom() : getZoom();
3816+
int zoom = autoScaleDisabled && parent != null ? parent.getZoom() : getZoom();
38173817
width = DPIUtil.pointToPixel(width, zoom);
38183818
height = DPIUtil.pointToPixel(height, zoom);
38193819
setSizeInPixels(width, height);

0 commit comments

Comments
 (0)