VRML Problem Solving Collected here and there (mostly "Java not working" related stuff) *********************************************** From: David Chamberlin Subject: Re: HELP: problem with EAI getBrowser call in COSMO 1.0 Newsgroups: comp.lang.vrml To: Brant Chamberlain Date: Tue, 30 Dec 1997 15:21:59 -0800 Organization: Silicon Graphics Path: news.unige.ch!news-ge.switch.ch!news.bme.hu!news.sztaki.hu!news.iif.hu!newscore.univie.ac.at!newsfeed.nacamar.de!newsfeed.direct.ca!newshub1.home.com!news.home.com!enews.sgi.com!fido.asd.sgi.com!news Lines: 86 Message-ID: <34A98217.9F15A2AD@sgi.com> References: NNTP-Posting-Host: doh.engr.sgi.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04C-SGI [en] (X11; I; IRIX 6.3 IP32) Brant already has his answer (answered through www-vrml) but I thought I'd repeat a few of the things that came up cuz they could be useful to others. First, my original reply: We've seen this problem before and believe that it's a netscape problem and it appears to only happen in the 4.x versions. The hack-around is to put the getBrowser() call in a loop: --- for (int count = 0; count < 10; count++) { browser = Browser.getBrowser (this); if (browser != null) break; try {Thread.sleep (200);} catch (InterruptedException ignored) {} System.out.println ("browser was null, trying again"); } if (browser == null) { throw new Error ("Failed to get the browser after 10 tries!"); } browser.print ("Got browser\n"); --- Might I also *strongly* suggest that you move your getBrowser() call out of the init() function and into the start() function. If you do it in the init() function and you hang on to the browser reference, if the user does a reload or goes back then forward, your applet will crash. The reason is that init() gets called once when the page is first visited. However every time the page is reloaded, the VRML browser gets destroyed and re-created. So any reference that you had to the browser (or any events, etc.) are bogus after re-loading. If you move that stuff to start(), which gets called each time you visit a page, then you should be fine. ---- Then when that didn't help, some more investigation was done and it was determined that the problem was that the applet he was trying to run was on his CLASSPATH. I've done some testing on this and it appears as though there's a bug in netscape where if you have the EAI applet on your CLASSPATH, then calls to getBrowser() will always fail. By simply removing the EAI applet's directory from the CLASSPATH (or moving the applet), everything seems to work fine. This is very odd indeed. However, note that it works just fine in IE4 (even with the applet on the CLASSPATH). -Dave Brant Chamberlain wrote: > > Hi, > > I've been wrestling with this problem for some time now: Can't get > a reference to the browser handle... > > I've tried using the static call Browser.getBrowser(this) which > throws a NullPointer exception. I then mocha'd the vrml.external.Browser > class file and found out that the static call is using the old JSObject > stuff anyway. > > I have found that the getBrowser function fails when > > embeds = (JSObject)doc.getMember("embeds"); > > is called. > > What's even more infuriating is that this problem dissapears on > other machines I've tested at my office. Is this a configuration issue? > Has anybody had similar experiences. Any help REALLY appreciated... > > Using Netscape 4.04 and Cosmo 1.02 > > Thanks in advance, > Brant Chamberlain > brantc@engine5.com -- David Chamberlin | email: chamber@sgi.com Cosmo Software | Pager: chamber_p@pager.sgi.com A Silicon Graphics Company | http://reality.sgi.com/chamber Phone: (650) 933-6414 | http://doh.engr/ From: Chris Thorne Subject: Re: Dealing with Netscape Java 1.1 CLASSPATH issues Sender: www-vrml-approval@vrml.org Tue, 11 Nov 97 15:08:27 WST Further to Justin's post and my earlier one (Re: Pb with EAI) on this subject, let me me say that the argument that java (+VRML) is very portable across platforms has taken a severe beating recently when we kept finding somthing would run on one person's machine but not on another. I realise this is a symptom of beta versions of several products (not a problem with Java itself) but still ... it has been a little disconcerting when added to all the other differences + bugs between browser implementations. We have been using JDK 1.1.x AWT and EAI and in many problem cases the differences were subtle and the way to get it working was not always sensible. As one who spent a great many hours solving a surprising number of variations on the problem of getting and applet to run with netscape and cosmo player let me provide a little catalogue of problems and results that no doubt will be familliar to many :) - and hopefully help those beating their heads against the wall. ================================ Running Communicator+Java 1.1.x + VRML (Win NT/95) Case 1: Using LiveConect (JavaScript) method to get Browser: Could not get embeds until I removed the path to the code base from the classpath (this was redundant as there is a "." in the classpath and also the html has codebase pointing there too). If I did not remove this part the get embeds returns null. ****Note that: I re-tested the Browser.getBrowser(this) (with latest jdk patch referred to by Justin) and it now works. This method does not not have the same problems - not affected by adding the redundant path reference into the classpath. **** In case 2, a big app only worked if the path to java40.jar was included in the CLASSPATH. This is thankfully not required for running now (with latest Netscape Communciator + Cosmo Player) - REMOVE it from CLASSPATH. In Case 3 we were using the first java patch for jdk1.1.x and at this stage Browser.getBrowser did not work. Your applet fails when you do a getSlot() on a null object returned from the getBrowser call. In Case 4 the problem was twofold: double-clicking on the initial html file it did not work on someones machine. If you dragged the html file into the Communicator icon instead of double-clciking - his problem went aaway. In this case there was also another issue: His controlling applet was not in the codebase but several dirs down. He could only get it to work if the applet reference in the starting html file had the directory slashes replaced with dots ("\"'s replaced with "."'s). ================================ The upshot: If you are using JDK 1.1.x AWT and EAI: 1 safest is no npcosmop.zip and java40.jar in your classpath for *running* Java+VRML but you may need npcosmop.zip and java40.jar there for compiling. 2 using browser = Browser.getBrowser(this); is now more reliable than the old JS method if you want to get access to VRML nodes . Regards, Chris ---------------------- From: Carissimi Subject: JAVA & VRML Newsgroups: comp.lang.java.advocacy,comp.lang.vrml,comp.lang.java.api,comp.lang.java.misc,comp.lang.java.programmer,comp.lang.java.security,comp.lang.java.setup,comp.lang.java.tech Date: Tue, 30 Dec 1997 20:41:13 +0000 I hope that someone can help me with this problem... On the same HTML page, I have 2 applets (called Campo and Creatore) and 1 VRML-world (called Mondo). The two applets communicate one with the other using the getApplet method. The applet Creatore communicates with the VRML world (Mondo) via the External Authoring Interface. So, in the HTML file, I have to give a name to the applets so that the getApplet method can run correctly, and I have to introduce the MAYSCRIPT attribute in the applet TAG of Creatore indicating that my applet can communicate with the VRML world. Here is the resulting HTML file: Now the problem: using this solution the two applets don't communicate and I get the exception "java.lang.ClassCastException: Campo" indicating me that I can't cast a variable "ap" from the class Applet to the class Campo. Naturally if I don't use the MAYSCRIPT attribute the two applets communicate without problems (but the applet Creatore can't communicate with Mondo.wrl). If anybody knows why this problem arise, please e-mail me or post-me. Bye, miki Hi, if you use MAYSCRIPT then you can't have applets communicating, if you don't use MAYSCRIPT the VRML doesn't work, so that is kind of a = =20 dilemma ! I don't know the solution ! Ciao ********************************************************** If I put Netscape's java40.jar in my CLASSPATH, I can compile my EAI code and get a connection to the VRML browser using this code: JSObject win = JSObject.getWindow(this); JSObject doc = (JSObject) win.getMember("document"); JSObject embeds = (JSObject) doc.getMember("embeds"); browser = (Browser) embeds.getSlot(0); As long as my code is perfect, everything is fine. However, even the slightest mistake or typo in my code will cause the compiler to give me several screens of strange errors, making debugging virtually impossible. Here's a sample error for a program with a simple spelling mistake in a variable name: java.lang.NoSuchMethodError: java.lang.SecurityManager: method getClassContext()[Ljava/lang/Class; not found at at java.util.ResourceBundle.getBundle(ResourceBundle.java:204) at sun.tools.javac.Main.initResource(Main.java:97) . . . I get normal error messages if java40.jar is not in the CLASSPATH. I'd prefer to leave it out and use "browser = Browser.getBrowser (this);" to get a handle to the browser, but that always seems to return null, even if I put it in a loop. Does anyone know how to get rid of the strange compiler errors? -Adam Fass ----- Adam, You did not mention which version of Netscape you are using nor which VRML browser. I use Netscape 4.0x with CosmoPlayer. If using CP make sure you have the latest release and not the beta, many fixes were implemented. According to the CosmoPlayer release notes getBrowser() will return null if java40.jar is in your CLASSPATH. Further note that CP requires you add its java files to your CLASSPATH. You can also use the following code as a workaround: Browser browser = null; for (int count = 0; count < 10; count++) { browser = Browser.getBrowser (this); if (browser != null) break; try {Thread.sleep (200);} catch (InterruptedException ignored) {} browser.print ("browser was null, trying again"); } if (browser == null) { throw new Error ("Failed to get the browser after 10 tries!"); } browser.print ("Got browser\n"); You may also take a look at my code at: http://www.cs.buffalo.edu/~pventura/BOIDS/ ********************************************************************** First, let me recommend that you upgrade to the final version of CP2.0 which is available at: http://cosmo.sgi.com/products/player Second, you are probably running into a known bug in recent versions of netscape. Due to this bug, the getBrowser() will sometimes return null at first, but will eventually work on subsequent tries. To get around this, you can put the getBrowser() call in a loop. Here's some boiler-plate code we've been passing out to hack around this problem: browser = null; for (int count = 0; count < 10; count++) { browser = Browser.getBrowser (this); if (browser != null) break; try {Thread.sleep (200);} catch (InterruptedException ignored) {} browser.print ("browser was null, trying again"); } if (browser == null) { throw new Error ("Failed to get the browser after 10 tries!"); } browser.print ("Got browser\n"); -Dave ********************************************************************** From: Jay Steele Subject: Cosmo EAI question Newsgroups: comp.lang.vrml To: www-vrml@vrml.org Date: Wed, 07 Jan 1998 17:35:59 -0400 Organization: MT&T Advanced Communications Path: news.unige.ch!news-ge.switch.ch!news-fra1.dfn.de!news-was.dfn.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!howland.erols.net!torn!news.dal.ca!news.mtt.net!news-admin Lines: 23 Message-ID: <34B3F53E.8E4C30C7@novafex.com> NNTP-Posting-Host: 142.176.7.210 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; I) There is some behaviour I don't understand in the Cosmo EAI "replaceWorld" command, and I can't seem to find any documentation describing it. When I call replaceWorld(...) the viewpoint in the Cosmo browser changes--sometimes. For example, if I load a scene and use the browser controls to spin and navigate, and then make a call to replaceWorld(...) again, it shift the view to some incoherent location.. It doesn't seem to consistently return the viewpoint to the default of (0, 0, 10), nor does it leave the view in the same location, it seems to shift the view by some random amount. I definitely don't have any Viewpoint objects in the string I'm sending--its just a Shape node with some geometry in it. I would prefer it if the view didn't change at all if I didn't have a Viewpoint node in the string I'm sending. Second best would be if it returned the view to the default value of (0, 0, 10). ---- Dunno if I responded to you Jay or not, but this is a known bug in 2.0. We'll have it fixed in the next release (no dates yet). *************************************************************************