Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  DisplayMode Changing & BufferStrategy=V.Buggy  (Read 3079 times)
0 Members and 1 Guest are viewing this topic.
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Posted 2002-11-29 22:27:29 »

i've been playing around with changing DisplayModes, and found that when combined with BufferStrategy its not just unstable, it simply doesn't work!

here is some cutdown code that demonstrates the sort of problems encountered.

also, in FullScreenFrame there are 2 lines (105 & 106) neither of which should be needed. However, by adding 1 or other (or both) of them I can get it to partially work. (but with allsorts of low-level exceptions being thrown up in native code)

Can some1 reassure me that its Sun code that is broken, not mine!
(A friend has also independantly attempted to solve the same problem, but hes come across the same bugs and crashes as well Huh )

FullScreenFrame.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class FullScreenFrame extends Frame
{
   private GraphicsDevice screenDevice;

   private DisplayMode defaultMode;

   boolean isWindowed = true;

   String [] modeNames; //this is a String representation of each of the supported display modes
   DisplayMode [] modes; //this is the [] of supported display modes

   public FullScreenFrame(JavaMonster jm, GraphicsDevice gd)
   {
      super("F12 windowed/fullScreen toggle | UP/DOWN ARROWS cycle to new resolution | ENTER apply new resolution");
      if(gd==null) gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

      this.screenDevice = gd;
      this.defaultMode = gd.getDisplayMode(); // bad assumption made here. Needs fixing before I forget

      /* 'just for debug' */
      addKeyListener(jm);
      addMouseListener(jm);
      addWindowListener(jm);
      /*end of 'just for debug' */

      setIgnoreRepaint(true);
      setResizable(false);
      setLayout(null);
      enableInputMethods(false);


      //this code initialises the modes [] and modeNames []
      // it also identifies the index of the default mode (defaultModeNumber)
      modes = screenDevice.getDisplayModes();
      modeNames = new String[modes.length];
      for(int i = 0;i < modes.length;i++)
      {
         if(modes[i].equals(defaultMode)) defaultModeNumber = i;
         DisplayMode cdm = modes[i];
         modeNames[i] = "("+(i+1)+"/" + modes.length +")"+
                        cdm.getWidth()+"x"+cdm.getHeight()+"x"+
                        cdm.getBitDepth()+"@ "+cdm.getRefreshRate();
      }


   }

   int defaultModeNumber;
   public int getDefaultModeNumber()
   {
      return defaultModeNumber;
   }

   public int getModeCount()
   {
      return modes.length;
   }

   public boolean isFullScreen()
   {
      return !isWindowed;
   }

   public String getModeName(int mode)
   {
      return modeNames[mode];
   }

   //allows calling by index (just a lazy method)
   public BufferStrategy setDisplayMode(boolean fullScreen, int mode)
   {
      return setDisplayMode(fullScreen, modes[mode]);
   }

   // sets the display mode of this Frame
   // if the frame is not already visible,
   // it will also be made visible
   public BufferStrategy setDisplayMode(boolean fullScreen, DisplayMode dm)
   {
      System.out.println("Changing to "+ (fullScreen?"Full Screen ":"Window ") +
                         dm.getWidth() + "x" + dm.getHeight() + "x" + dm.getBitDepth());

      if(fullScreen && screenDevice.isFullScreenSupported()) //switching to fullscreen mode (if its supported)
      {
         if(isWindowed)
         {
            dispose(); //dispose of the window ...
            setUndecorated(true); //...so the decoration can be removed
            screenDevice.setFullScreenWindow(this);
         }

         if(screenDevice.isDisplayChangeSupported() && !screenDevice.getDisplayMode().equals(dm))
         {
            screenDevice.setDisplayMode(dm);
            createBufferStrategy();
         }
         else if(isWindowed) createBufferStrategy();
         isWindowed = false;
      }
      else //we are changing to window mode
      {
         if(!isWindowed)
         {
            //screenDevice.setDisplayMode(defaultMode); //this line shouldn't be needed
            //screenDevice.setFullScreenWindow(null); // this line shouldn't be needed
            dispose(); //dispose of the window...
            setUndecorated(false); //...so it can be changed to a decorated window
            isWindowed=true;
         }

         Rectangle screenSize = screenDevice.getDefaultConfiguration().getBounds();
         setBounds(screenSize.x + (screenSize.width -dm.getWidth())/2,
                   screenSize.y + (screenSize.height-dm.getHeight())/2,
                   dm.getWidth(), dm.getHeight()); //centres the window
         if(!isVisible())
         {
            show();
            createBufferStrategy();
         }
      }
      return getBufferStrategy();
   }

   public static final boolean USE_BASIC_BUFFERSTRATEGY_ONLY = false;
   private void createBufferStrategy()
   {
      if(USE_BASIC_BUFFERSTRATEGY_ONLY) return;
      createBufferStrategy(2);
   }
}


JavaMonster.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
import java.util.Random;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.*;
import java.io.*;
class JavaMonster implements Runnable, MouseListener, WindowListener, KeyListener
{
   boolean running = true; //just afew flags for changing mode
   boolean changeToFullScreen = false;
   boolean changeMode = false;

   int currentMode;
   int nextMode;

   int modeChange=0;

   FullScreenFrame fsf;
   Random random = new Random();
   BufferStrategy strategy;

   public JavaMonster()
   {
      fsf = new FullScreenFrame(this,null);
      nextMode = currentMode = fsf.getDefaultModeNumber();
      strategy = fsf.setDisplayMode(false,currentMode);
      new Thread(this).start();
   }

   public void run()
   {
      while(running)
      {
         if(modeChange!=0)
         {
            nextMode+=modeChange;
            if(nextMode<0 || nextMode >= fsf.getModeCount()) nextMode-=modeChange;
            modeChange=0;
         }

         if(changeMode)
         {
            strategy = fsf.setDisplayMode(changeToFullScreen,nextMode);
            currentMode = nextMode;
            changeMode = false;
         }

         Graphics2D g2 = (Graphics2D)strategy.getDrawGraphics();
         g2.setColor(new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255)));
         g2.fillRect(0,0,fsf.getWidth(),fsf.getHeight());
         g2.setColor(Color.black);
         g2.drawString("Current Mode = " + fsf.getModeName(currentMode) + (changeToFullScreen?" FullScreen":" Windowed"), 20, 50);
         g2.drawString("Next Mode = " + fsf.getModeName(nextMode) + (changeToFullScreen?" FullScreen":" Windowed"), 20, 80);
         g2.dispose();
         strategy.show();

         try
         {
            Thread.currentThread().sleep(500);
         }
         catch(Exception e){}
      }
      fsf.dispose();
   }

   public static void main(String [] args) throws Exception
   {
      new JavaMonster();
   }

   //debug listeners
   public void mouseClicked(MouseEvent e) {}
   public void mouseEntered(MouseEvent e) {}
   public void mouseExited(MouseEvent e) {}
   public void mousePressed(MouseEvent e) {}
   public void mouseReleased(MouseEvent e) {}
   public void mouseDragged(MouseEvent e) {}
   public void mouseMoved(MouseEvent e) {}

   public void keyPressed(KeyEvent e)
   {
      switch(e.getKeyCode())
      {
         case KeyEvent.VK_ESCAPE: //Escape to kill the Thread (and eventually dispose of the Window)
         running = false;
         return;
         case KeyEvent.VK_UP: //up arrow to cycle up through supported resolutions
         modeChange=1;
         return;
         case KeyEvent.VK_DOWN: //down arrow to cycle down through supported resolutions
         modeChange=-1;
      }
   }

   public void keyReleased(KeyEvent e)
   {
      switch(e.getKeyCode())
      {
         case KeyEvent.VK_F12: //F12 toggles FullScreen
         changeToFullScreen=!changeToFullScreen;
         /* follows through */
         case KeyEvent.VK_ENTER: //Enter to apply new resolution selection
         changeMode=true;
      }
   }

   public void keyTyped(KeyEvent e) {}

   public void windowClosing(WindowEvent e)
   {
      System.out.println("Window closing");
      running = false;
   }

   public void windowActivated(WindowEvent e) {System.out.println("Window activated");}
   public void windowClosed(WindowEvent e) {System.out.println("Window closed");}
   public void windowDeactivated(WindowEvent e) {System.out.println("Window deactivated");}
   public void windowDeiconified(WindowEvent e) {System.out.println("Window deiconified");}
   public void windowIconified(WindowEvent e) {System.out.println("Window iconified");}
   public void windowOpened(WindowEvent e) {System.out.println("Window opened");}
}

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline trembovetski

Senior Duke




If only I knew what I'm talking about!


« Reply #1 - Posted 2002-11-30 05:18:52 »

Certainly, if you see exceptions or crashes, it's most likely our fault (with notable exceptions of some buggy video drivers that are out there).

I don't see anything really broken in your code, and I did see some problems when switching display modes in fullscreen, when running it on 1.4.1_01. The things sort of improved when I added a 2 seconds delay between the
 screenDevice.setDisplayMode(dm);
and
createBufferStrategy();

What jdk version were you using?

We've made a lot of full screen fixes in the upcoming patch release (1.4.1_02, will be out sometime in Q1'03), I'll try your app with the new build to see if we've covered these problems.
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #2 - Posted 2002-11-30 11:39:50 »

ah ok,

well, I was using jdk1.4.0, but my friend was using 1.4.1_01 and encountered the same problems.

In my original post, I ommited telling you how exactly to replicate the problems - oops Smiley

anyhow, here is the sequence that kills it.

The program starts up with a Window that occupies the entire screen.

1) select a different screen size
2) switch to fullscreen.
3) switch back to window mode

The problems start now. Depending on which lines are commented out, several things can happen.

Both lines 107 & 108 are Commented out

The repaint code will nolonger be having any effect on the Window. (its as if the BufferStrategy that was created is in an invalid state).
If you then switch back to fullscreen, a low-level exception is thrown (somewhere underneath GraphicsDevice.setDisplayMode(DisplayMode))

Only line 107 is Commented out

Same as above, but if you now stay in windowed mode, and switch to a different resolution (down arrow, then enter) you get a JVM crash in native code that looks something like this :-

An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x831F1BB7
Function=[Unknown.]
Library=(N/A)'

(some other stuff ommited)

Dynamic libraries:
0x7D750000 - 0x7D76D000       C:\WINDOWS\SYSTEM\IMAGEHLP.DLL

(some other stuff ommited)

# Java VM: Java HotSpot(TM) Client VM (1.4.0-b92 mixed mode)



neither 107 or 108 are Commented out

the repaints work, BUT they draw over the top of the Windows decoration (even though the window is decorated). Its as if the Frame is in a Windowed Exclusive Mode (the repaints occur ontop of every other window, even if the Frame is obscured!)
Also, any subsequent FullScreen->Windowed mode switches cause a none terminal Exception (originating from the EventDispatchThread)

I will try adding the 2 second delay, and switching to 1.4.1 - see if that improves matters.

I have tried adding the 2 second delay, and it made no difference. (im downloading 1.4.1 as I type)

I now have 1.4.1_01, and the same problems occur Sad, even with the 2 second delay

p.s. many thanx for the prompt reply!

rob,

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trembovetski

Senior Duke




If only I knew what I'm talking about!


« Reply #3 - Posted 2002-12-01 07:04:32 »

The alt+tabbing out and back to the fullscreen app was one of the things we were working on recently, so hopefully your problems are fixed now. I'll let you know how it goes.
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #4 - Posted 2002-12-01 12:59:36 »

ok, i've got an update :-

using 1.4.1_01, i've managed to find a work-around.
(im not sure it'll work with 1.4.0 - but its possible it will)

the 3 lines of the work-around are highlighted.

(1) before disposing of a FullScreen window, you *HAVE* to call GraphicsDevice.setFullScreenWindow(null); (line 109)

(2) there is some validation code deep down in Component that needs calling before createBufferStrategy will return a valid Strategy.
Both pack() and setBounds(x,y,width,height) call this code, though I havn't pinpointed exactly what code it is.
(line 117)

(3) getBufferStrategy will still return an invalid Strategy, until BufferStrategy.show() is called.
Once this has been done, any future calls to getBufferStrategy() will return a valid, and fully usable strategy! (line 121)

so, can I have your promise that it'll be working properly by 1.4.1_02  Grin

oh, and here is the code that implements the fix.

FullScreenFrame.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class FullScreenFrame extends Frame
{
   private GraphicsDevice screenDevice;

   private DisplayMode defaultMode;

   boolean isWindowed = true;

   String [] modeNames; //this is a String representation of each of the supported display modes
   DisplayMode [] modes; //this is the [] of supported display modes

   public FullScreenFrame(JavaMonster jm, GraphicsDevice gd)
   {
      super("F12 windowed/fullScreen toggle | UP/DOWN ARROWS cycle to new resolution | ENTER apply new resolution");
      if(gd==null) gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

      this.screenDevice = gd;
      this.defaultMode = gd.getDisplayMode(); // bad assumption made here. Needs fixing before I forget

      /* 'just for debug' */
      addKeyListener(jm);
      addMouseListener(jm);
      addWindowListener(jm);
      /*end of 'just for debug' */

      setIgnoreRepaint(true);
      setResizable(false);
      setLayout(null);
      enableInputMethods(false);


      //this code initialises the modes [] and modeNames []
      // it also identifies the index of the default mode (defaultModeNumber)
      modes = screenDevice.getDisplayModes();
      modeNames = new String[modes.length];
      for(int i = 0;i < modes.length;i++)
      {
         if(modes[i].equals(defaultMode)) defaultModeNumber = i;
         DisplayMode cdm = modes[i];
         modeNames[i] = "("+(i+1)+"/" + modes.length +")"+
                        cdm.getWidth()+"x"+cdm.getHeight()+"x"+
                        cdm.getBitDepth()+"@ "+cdm.getRefreshRate();
      }


   }

   int defaultModeNumber;
   public int getDefaultModeNumber()
   {
      return defaultModeNumber;
   }

   public int getModeCount()
   {
      return modes.length;
   }

   public boolean isFullScreen()
   {
      return !isWindowed;
   }

   public String getModeName(int mode)
   {
      return modeNames[mode];
   }

   //allows calling by index (just a lazy method)
   public BufferStrategy setDisplayMode(boolean fullScreen, int mode)
   {
      return setDisplayMode(fullScreen, modes[mode]);
   }

   // sets the display mode of this Frame
   // if the frame is not already visible,
   // it will also be made visible
   public BufferStrategy setDisplayMode(boolean fullScreen, DisplayMode dm)
   {
      System.out.println("Changing to "+ (fullScreen?"Full Screen ":"Window ") +
                         dm.getWidth() + "x" + dm.getHeight() + "x" + dm.getBitDepth());

      if(fullScreen && screenDevice.isFullScreenSupported()) //switching to fullscreen mode (if its supported)
      {
         if(isWindowed)
         {
            dispose(); //dispose of the window ...
            setUndecorated(true); //...so the decoration can be removed
            screenDevice.setFullScreenWindow(this);
         }

         if(screenDevice.isDisplayChangeSupported() && !screenDevice.getDisplayMode().equals(dm))
         {
            screenDevice.setDisplayMode(dm);
            createBufferStrategy();
         }
         else if(isWindowed) createBufferStrategy();
         isWindowed = false;
      }
      else //we are changing to window mode
      {
         if(!isWindowed)
         {
            System.out.println("currently FullScreen");
            //screenDevice.setDisplayMode(defaultMode); //this line shouldn't be needed (it isn't needed for my fix/hack)
            screenDevice.setFullScreenWindow(null); // (1)
            dispose(); //dispose of the window...
            setUndecorated(false); //...so it can be changed to a decorated window
            isWindowed=true;
         }

         if(!isVisible())
         {
            pack(); // (2) //setBounds(x,y,width,height); also works here
            show();
            createBufferStrategy();

            getBufferStrategy().show(); // (3)
         }

         Rectangle screenSize = screenDevice.getDefaultConfiguration().getBounds();
         setBounds(screenSize.x + (screenSize.width -dm.getWidth())/2,
                   screenSize.y + (screenSize.height-dm.getHeight())/2,
                   dm.getWidth(), dm.getHeight()); //centres the window
      }
      return getBufferStrategy();
   }

   public static final boolean USE_BASIC_BUFFERSTRATEGY_ONLY = false;
   private void createBufferStrategy()
   {
      if(USE_BASIC_BUFFERSTRATEGY_ONLY) return;
      createBufferStrategy(2);
   }
}


JavaMonster.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
import java.util.Random;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.*;
import java.io.*;
class JavaMonster implements Runnable, MouseListener, WindowListener, KeyListener
{
   boolean running = true; //just afew flags for changing mode
   boolean changeToFullScreen = false;
   boolean changeMode = false;

   int currentMode;
   int nextMode;

   int modeChange=0;

   FullScreenFrame fsf;
   Random random = new Random();
   BufferStrategy strategy;

   public JavaMonster()
   {
      fsf = new FullScreenFrame(this,null);
      nextMode = currentMode = fsf.getDefaultModeNumber();
      strategy = fsf.setDisplayMode(false,currentMode);
      new Thread(this).start();
   }

   public void run()
   {
      while(running)
      {
         if(modeChange!=0)
         {
            nextMode+=modeChange;
            if(nextMode<0 || nextMode >= fsf.getModeCount()) nextMode-=modeChange;
            modeChange=0;
         }

         if(changeMode)
         {
            strategy = fsf.setDisplayMode(changeToFullScreen,nextMode);
            currentMode = nextMode;
            changeMode = false;
         }

         Graphics2D g2 = (Graphics2D)strategy.getDrawGraphics();
         g2.setColor(new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255)));
         g2.fillRect(0,0,fsf.getWidth(),fsf.getHeight());
         g2.setColor(Color.black);
         g2.drawString("Current Mode = " + fsf.getModeName(currentMode) + (changeToFullScreen?" FullScreen":" Windowed"), 20, 50);
         g2.drawString("Next Mode = " + fsf.getModeName(nextMode) + (changeToFullScreen?" FullScreen":" Windowed"), 20, 80);
         g2.dispose();
         strategy.show();

         try
         {
            Thread.currentThread().sleep(500);
         }
         catch(Exception e){}
      }
      fsf.dispose();
   }

   public static void main(String [] args) throws Exception
   {
      new JavaMonster();
   }

   //debug listeners
   public void mouseClicked(MouseEvent e) {}
   public void mouseEntered(MouseEvent e) {}
   public void mouseExited(MouseEvent e) {}
   public void mousePressed(MouseEvent e) {}
   public void mouseReleased(MouseEvent e) {}
   public void mouseDragged(MouseEvent e) {}
   public void mouseMoved(MouseEvent e) {}

   public void keyPressed(KeyEvent e)
   {
      switch(e.getKeyCode())
      {
         case KeyEvent.VK_ESCAPE: //Escape to kill the Thread (and eventually dispose of the Window)
         running = false;
         return;
         case KeyEvent.VK_UP: //up arrow to cycle up through supported resolutions
         modeChange=1;
         return;
         case KeyEvent.VK_DOWN: //down arrow to cycle down through supported resolutions
         modeChange=-1;
      }
   }

   public void keyReleased(KeyEvent e)
   {
      switch(e.getKeyCode())
      {
         case KeyEvent.VK_F12: //F12 toggles FullScreen
         changeToFullScreen=!changeToFullScreen;
         /* follows through */
         case KeyEvent.VK_ENTER: //Enter to apply new resolution selection
         changeMode=true;
      }
   }

   public void keyTyped(KeyEvent e) {}

   public void windowClosing(WindowEvent e)
   {
      System.out.println("Window closing");
      running = false;
   }

   public void windowActivated(WindowEvent e) {System.out.println("Window activated");}
   public void windowClosed(WindowEvent e) {System.out.println("Window closed");}
   public void windowDeactivated(WindowEvent e) {System.out.println("Window deactivated");}
   public void windowDeiconified(WindowEvent e) {System.out.println("Window deiconified");}
   public void windowIconified(WindowEvent e) {System.out.println("Window iconified");}
   public void windowOpened(WindowEvent e) {System.out.println("Window opened");}
}


Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline MGodehardt

Junior Duke




why does the chicken cross the road?


« Reply #5 - Posted 2002-12-06 08:58:03 »

yes with getBufferStrategy().show() it works

window -> fullscreen -> window

but call GraphicsDevice.getAvailableAcceleratedMemory()

when in windowed mode, it says 0 after switching back to windowed d'oh!
Offline MGodehardt

Junior Duke




why does the chicken cross the road?


« Reply #6 - Posted 2003-08-26 08:09:44 »

Looks like JDK 1.4.2 ( build 1.4.2-b28) fixed the problem with fullscreen.  Grin

I recompiled a game and now i can toggle between windowed and fullscreen exclusive without any crash, also the available VRAM

getAvailableAcceleratedMemory()

is now reporting != 0 when leaving fullscreen mode.
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #7 - Posted 2003-08-26 08:49:40 »

nah, its definitly still fubared. :-/

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline MGodehardt

Junior Duke




why does the chicken cross the road?


« Reply #8 - Posted 2003-08-26 11:30:18 »

I have working code ( but i cant post it here )

I have a Windows 98 SE pc with DirectX 8.1 on a NVidia GeForce2 MX

First i create a Frame, make it windowed and use double buffering ( 2 backbuffers ), when i press ALT+ENTER my code switches the frame to Fullscreen and next press on ALT+ENTER toggles it back to windowed.

I have no crash, backbuffers are fine, free reported VRAM is fine, no grpahic glitches, all works fine.

Much Much better than v1.4.1.

Maybe there are some other bugs, but its getting better.
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #9 - Posted 2003-08-26 12:56:34 »

Toggling decoration on/off when moving between windowed and fullscreen is still broken. (due to buggy code in dispose()Wink

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline MGodehardt

Junior Duke




why does the chicken cross the road?


« Reply #10 - Posted 2003-08-27 06:03:22 »

I can tell you how my code works. First i create a Frame in windowed mode, then i apply following attributes to it.

1  
2  
3  
4  
5  
6  
7  
8  
setBackground(Color.darkGray);
setIgnoreRepaint(true);
setResizable(false);
setLayout(null);
setSize(itsWidth, itsHeight);
setUndecorated(false);
setVisible(true);
toFront();


now i have a windowed frame, i use 2 BackBuffers for rendering with createBufferStrategy(2)

rendering is ok, all works fine ( i get 150fps without any rendering only backbuffer flipping, so with 30fps i have a lot of time to do some rendering )

now i can press ALT+ENTER and my code will execute the following code sequence

1  
2  
3  
4  
5  
6  
itsOldMode = gd.getDisplayMode();
gd.setFullScreenWindow(this);
validate();

gd.setDisplayMode(new DisplayMode(itsWidth, itsHeight, itsBitDepth, DisplayMode.REFRESH_RATE_UNKNOWN));
validate();


i am now in fullscreen exclusive mode ! the caption is NOT VISIBLE and rendering works fine !

BUT you have to sync rendering with mode switching, i use a mutex for this, i have a variable which enables or disables rendering ( canRender ) and this variable is synced with the mutex ( very important )

now if the user presses ALT+ENTER again following code is executed

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
if ( null != itsOldMode )
{
    gd.setDisplayMode(itsOldMode);
    validate();
}

gd.setFullScreenWindow(null);
validate();
setSize(itsInsets.left + itsWidth + itsInsets.right, itsInsets.top + itsHeight + itsInsets.bottom);
validate();
           
itsOldMode = null;


i have now a windowed frame WITH CAPTION everything is fine rendering works and available VRAM is now OK ( it happened it version 1.4.1 switching from fullscreen to windowed, i got 0 bytes free from gd.getAvailableAcceleratedMemory() )

the validate helps a lot

P.S.: I use the same Bit Depth in windowed and fullscreen mode ( which is 16Bit )
Offline MGodehardt

Junior Duke




why does the chicken cross the road?


« Reply #11 - Posted 2003-08-27 12:41:43 »

Quote
Toggling decoration on/off when moving between windowed and fullscreen is still broken. (due to buggy code in dispose()Wink


yes this is correct, forget everything is said before. I did some testing and found the following solution.

Use two Frames, one for windowed mode and one for fullscreen exclusive. Switching a Frame from Fullscreen to Windowed is buggy, also the dispose of a Fullscreen Exclusive Frame with Hardware Flipping ( FlipBufferStrategy ) is very buggy, when u dispose such a window it throws exception ( i hope sun will fix this soon).

So with 2 Frames you can switch between windowed and fullscreen without any problem, i use a static variable which gets the current visible frame ( the other one is hidden ).

Thats the workaround for the moment.
Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #12 - Posted 2003-08-27 16:45:07 »

yeah, ive been using that work-around for some time now.

However, even the work-around is flawed.

After several mode/resolution switches, you get a JVM crash in the resource disposer. (part of the Garbage Collector)

I guess its not disposing of the vram used for the back buffers correctly.

Anyhow, Sun knows about all the problems, and have s'posedly fixed them.
Though I guess we won't know for sure until 1.5 is available.

p.s. This is the disposer crash  :-

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x5
Function=[Unknown.]
Library=(N/A)

NOTE: We are unable to locate the function name symbol for the error
      just occurred. Please refer to release documentation for possible
      reason and solutions.


Current Java thread:
      at sun.java2d.DefaultDisposerRecord.invokeNativeDispose(Native Method)
      at sun.java2d.DefaultDisposerRecord.dispose(DefaultDisposerRecord.java:25)
      at sun.java2d.Disposer.run(Disposer.java:102)
      at java.lang.Thread.run(Thread.java:534)
.....
<snip>

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline MGodehardt

Junior Duke




why does the chicken cross the road?


« Reply #13 - Posted 2003-09-01 23:15:04 »

Today i got mail from a sun developer, i entered a bug report 6 month ago and got a reply now *sighs*

these guys must be very busy at the moment.

Abuse i will report our problem to the developer and he will look into the problem and with some luck it will be fixed in the next release.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (53 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (43 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!