Hello Guest

[FIXED] Display.setParent resizing clips mouse coordinates - Nightly 11.8. WINDOWS

  • 2 Replies
The mouse coordinates are clipped to the original window size on the windows nightly from 11.8. (not checked with other platforms).
The following test case shows that DisplayImplementation.getWidth() doesn't change while resizing using Canvas:
Code: [Select]
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicReference;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

 * @author Matthias Mann
public class Test {
   private static boolean closeRequested = false;
   final static AtomicReference<Dimension> newCanvasSize = new AtomicReference<Dimension>();
   public static void main(String[] args)
      Frame frame = new Frame("Test");
      frame.setLayout(new BorderLayout());
      final Canvas canvas = new Canvas();
      canvas.addComponentListener(new ComponentAdapter() {
         public void componentResized(ComponentEvent e)
      frame.addWindowFocusListener(new WindowAdapter() {
         public void windowGainedFocus(WindowEvent e)
      frame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e)
            closeRequested = true;
      frame.add(canvas, BorderLayout.CENTER);
      try {
         frame.setPreferredSize(new Dimension(1024, 786));
         frame.setMinimumSize(new Dimension(800, 600));
         Dimension newDim;
         Field f = Display.class.getDeclaredField("display_impl");
         Object di = f.get(null);
         Method m = di.getClass().getMethod("getWidth");
         while(!Display.isCloseRequested() && !closeRequested)
            newDim = newCanvasSize.getAndSet(null);
            if (newDim != null)
               GL11.glViewport(0, 0, newDim.width, newDim.height);
                System.out.println(newDim.width + " " + m.invoke(di));

      } catch (Exception e) {

Ok more information as to why this is a critical regression:

By default the the mouse movement is clipped to the Display size. With this bug the size values used by Mouse are not updated when resizing using Display.setParent().
This causes the mouse movement to be clipped to the original display size.

A work around is to disable clipping of mouse coordinates using
Code: [Select]
Mouse.setClipMouseCoordinatesToWindow(false); // new in LWJGL 2.8or using:
Code: [Select]
So most apps written against 2.7.x using the Canvas based resizing will break.


Offline kappa

  • *****
  • 1316
this should be fixed in svn now.

thx for finding and reporting.