Black screen in applet after using 'streaming' java classes

Started by kingpig, December 07, 2009, 17:24:31

Previous topic - Next topic

kingpig

Greetings,

I have a problem with loading an LWJGL applet.
First I have created simple demo, which loads a .obj file
and displays it. Converting this into applet gave only
a black window. I have found guilty fragment of code:

File openFile = new File(fileName);
FileInputStream fis = new FileInputStream(openFile);


I took code from java.org.lwjgl.test.applet.GearsApplet and
noticed, that creating FileInputStream object, or BufferedReader object (or similar)
anywhere in that code is causing black screen instead of rotating gears.
Total confusion  >:(

kappa

do you get any output or error message on the java console?

kingpig

Quote from: javalwjgl on December 07, 2009, 17:29:33
do you get any output or error message on the java console?

Sorry, I'm quite new to this all Java stuff and I don't know how to obtain that console output  :-\
I tried to launch 'Java console' from 'Web-Developer' add-on in Firefox, but it's not giving effects.
Once I was writing something in Java3d and I remember, that Java console was appearing when error occurred,
but now with this LWJGL applet I have no clue.
I know it's not a place for asking about that, but how can I receive those errors or messages you are asking for in this case?  ;)

kappa

you can enable the java console from the java control panel, (found in the windows control panel).

click the Advanced Tab -> Java Console -> Check 'Show Console'
click apply and run the applet again.

kingpig

And here's the problem: applet is trying to access local file system, causing 'AccessControlException: access denied' exception.
A .jar file needs to be signed first (lot of stuff on the net how to do that).

So nothing is blocked - black screen is only caused by that exception  :-\
I think I will not remove this post - maybe a clue about Java Console will be handy for beginners  ;)
In Ubuntu Java Console can also be enabled in Java Control Panel.

Thank you for your attention  :)

broumbroum

Quote from: kingpig on December 08, 2009, 10:23:00
And here's the problem: applet is trying to access local file system, causing 'AccessControlException: access denied' exception.
A .jar file needs to be signed first (lot of stuff on the net how to do that).
(...)
AccessControlException means the access to the resource or function is denied because the securityManager does not GRANT the privileges. It's security beyond an Applet context. If it is signed, then you may add callbacks on PRIVILEGED ACTIONS such as, basically:
AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                // privileged code goes here, for example:
                System.loadLibrary("awt");
                return null; // nothing to return
            }
        });

Globally, any Java SDK function that tells to check for a SecurityManager context, namely the AccessControlContext. You can propagate such an AccessControlContext by using the Applet initial context :
class SecuredApplet extends JApplet {

AccessControlContext acc = null;
public  void init() {
acc = AccessController.getContext();
AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                // privileged code goes here, for example:
                System.loadLibrary("awt");
                return null;
            }
        }, acc); // here you garranty that the acc of the Applet will be used to grant the privileges

}
}

PrivilegedAction does ensure that you are in the privileged context where Permissions are fully checked for grant or deny.
Individual Permissions are GRANTED by the system java.policy file. See further on Permissions for more..