Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  Strange Deadlock in Window.setBackground()  (Read 1084 times)
0 Members and 1 Guest are viewing this topic.
Offline drakesword

Junior Member


Medals: 1



« Posted 2011-09-24 06:55:21 »

So 1 out of 150 application launches causes a deadlock in the java vm. I traced the code down to a single line

1  
w.setBackground(Color.GREEN);


Where w is a Window object.

Like I said this does not happen each and every launch just 1/150.

What I mean by deadlock is in my terminal window I can do ctrl C and there is no response  Shocked. Ctrl Z kills the process but leaves the window open (in fullscreen ... with no decorations I mind you).

Any ideas? Maybe a delay from creating the window to changing properties?
Online CommanderKeith
« Reply #1 - Posted 2011-09-24 08:15:48 »

Do you call that method on the event dispatch thread (EDT)?

Try http://download.oracle.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLater(java.lang.Runnable)

Offline drakesword

Junior Member


Medals: 1



« Reply #2 - Posted 2011-09-24 20:01:47 »

I Create a JFrame. Remove decoration and remove re sizable so it is a plain screen. Then I set the full screen window of the graphicsdevice to the jframe. Then I use getFullScreenWindow and set font, background, and foreground in that order. Deadlock occurs at the set background. Figured if I commented it out it would just lock up at the set foreground. I probably am not setting enough time between creating the full screen window and getting it again. Its probably giving me some other window.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2011-09-24 20:17:14 »

As CommanderKeith said: do you call that method on the event dispatch thread (EDT)?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline lhkbob

JGO Knight


Medals: 32



« Reply #4 - Posted 2011-09-24 22:28:23 »

If you don't know what the EDT is, then you're probably not doing it right.

Offline drakesword

Junior Member


Medals: 1



« Reply #5 - Posted 2011-09-25 03:53:47 »

No not from edt. Should I be?
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2011-09-25 04:03:39 »

Yes. Only manipulate AWT and Swing objects on the AWT event dispatching thread or you'll get deadlocks and weirdness, pure and simple.

Cas Smiley

Offline nsigma
« Reply #7 - Posted 2011-09-25 13:59:31 »

I Create a JFrame. Remove decoration and remove re sizable so it is a plain screen. Then I set the full screen window of the graphicsdevice to the jframe. Then I use getFullScreenWindow and set font, background, and foreground in that order. Deadlock occurs at the set background. Figured if I commented it out it would just lock up at the set foreground. I probably am not setting enough time between creating the full screen window and getting it again. Its probably giving me some other window.

While I'd agree with everyone telling you to put everything on the EDT, that still might not fix the problem.  Why are you not setting up all the properties (font, foreground, background, etc,.) on the frame prior to making it fullscreen?  Various things I've read (though nothing I'd call concrete proof - anyone?) suggest that bits of FSEM can / will happen asynchronously, and the window might not be fully set up by the time you call getFullScreenWindow(), and therefore the native peer not in any mood to play ball!  Smiley

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Cero
« Reply #8 - Posted 2011-09-25 14:06:44 »

I Create a JFrame. Remove decoration and remove re sizable so it is a plain screen. Then I set the full screen window of the graphicsdevice to the jframe. Then I use getFullScreenWindow and set font, background, and foreground in that order. Deadlock occurs at the set background. Figured if I commented it out it would just lock up at the set foreground. I probably am not setting enough time between creating the full screen window and getting it again. Its probably giving me some other window.

While I'd agree with everyone telling you to put everything on the EDT, that still might not fix the problem.  Why are you not setting up all the properties (font, foreground, background, etc,.) on the frame prior to making it fullscreen?  Various things I've read (though nothing I'd call concrete proof - anyone?) suggest that bits of FSEM can / will happen asynchronously, and the window might not be fully set up by the time you call getFullScreenWindow(), and therefore the native peer not in any mood to play ball!  Smiley

Yeah try to have setFullScreenWindow your last command, I remember it gets messed up if you don't

In my Java2D Display Manager, which I don't use for fullscreen anymore, but it did work, I have something like
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  
private void init(Frame fr)
    {
       ourDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0]; //failsafe
       
        //find primary screen device
       GraphicsDevice[] allDevices;
        allDevices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        for (int i=0;i<allDevices.length;i++)
       {
              java.awt.Rectangle bounds = allDevices[i].getDefaultConfiguration().getBounds();
           java.awt.Point origin = bounds.getLocation();
           if (origin.x == 0 && origin.y == 0 && allDevices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN)
           {
              ourDevice = allDevices[i];
              break;
           }
       }

        if (fullscreen)
        {
            fr.setUndecorated(true); // Sun Java Bug ID: 5034393
                                 // Undecorated BEFORE display sets
           ourDevice.setFullScreenWindow(fr);
            int colordepth = ourDevice.getDisplayMode().getBitDepth();
            try
            {
                  ourDevice.setDisplayMode(new DisplayMode(width,height,colordepth,0));
            }
            catch(IllegalArgumentException k) // failsafe
           {
               k.printStackTrace();
                width = FAILSAFE_WIDTH;
                height = FAILSAFE_HEIGHT;
                ourDevice.setDisplayMode(new DisplayMode(width,height,colordepth,0));
            }
            System.out.print("Fullscreen Mode: ");
        }
        else
        {
            fr.setVisible(true); //otherwise bufferStrategy throws 'Component must have a valid peer' Exception.
           fr.setBounds(0,0,width,height);
            fr.setLocationRelativeTo(null); // middle of screen
           System.out.print("Window Mode: ");
        }
    }

Offline drakesword

Junior Member


Medals: 1



« Reply #9 - Posted 2011-10-03 14:09:34 »

Thanks for the sample. I was doing those in that order. I set what settings that I could in the EDT. Then what I couldn't I set ater a short delay. I have yet to encounter a deadlock.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2011-10-03 14:34:31 »

Short delay = hackery. Expect a deadlock.

Cas Smiley

Offline drakesword

Junior Member


Medals: 1



« Reply #11 - Posted 2011-10-03 14:52:56 »

Sometimes a hack is required XD. As long as I don't get a lock while developing I am cool. I will look into it more in detail after most - all of the core features are finished before I start making content.
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.

Riven (18 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (30 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (41 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!