Smith, David wrote:

I looked at the bug parade, and there is a bug fix
as well as a workaround for this problem in Java3D1.3_beta1.
(Now you know why I wanted to see what version I was running :)

The error is this:

Modeler.Command.ExportToJPEG.Execute(ExportToJPEG.java:60)
    D:\gedavesm\src\java\Modeler\Test1.jpg
java.lang.NullPointerException
       at javax.media.j3d.Canvas3D.renderOffScreenBuffer(Canvas3D.java:1921)
       at Modeler.Command.ExportJPEGAsThread.run(ExportToJPEG.java:152)

The description is :

"NullPointerException throws in offscreen canvas
renderOffScreenBuffer if :

(1) It is invoke in Canvas3D callback function
(2) The View of this offscreen canvas is shared by
   an onScreen canvas
(3) The renderOffScreenBuffer() is invoke immediately
   in the same frame when offscreen canvas created."

I am doing both 2 & 3.

The Workaround was described as saying :

"Wait for one more frame before invoke
renderOffScreenBuffer after Offscreen canvas is created."

Which I wasn't doing because I thought it was 'Fixed'.
So I decided to wait for a frame.  I tried the following:

View  view = ...
view.addCanvas3D( offscreencanvas );
view.stopView();
view.renderOnce();
view.startView();

offscreencanvas.renderOffScreenBuffer();
offscreencanvas.waitForOffScreenRendering();
view.removeCanvas3D( offscreencanvas );

BufferedImage bImageRet = offscreencanvas.
                              getOffScreenBuffer().
                                 getImage();

But I don't get what's being displayed on my on-screen
buffer.

Does anyone have advice on rendering to an offscreen buffer?


This bug 4513765 is fixed so there is no need for workaround if
you're using Java3D v1.3.1 release. It is possible there is some
setup not correct in your applications.

Check out the offscreen rendering examples
OffScreenTest and  PrintFromButton
in Java3D SDK distribution directory and the attach one.

- Kelvin
--------------
Java 3D Team
Sun Microsystems Inc.



/*
 *
 *    "@(#)SimpleOffScreenTest.java 1.1 99/11/17"
 *
 * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.awt.*;
import java.applet.*;
import java.awt.image.BufferedImage;
import javax.media.j3d.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.applet.MainFrame;

public class SimpleOffScreenTest extends Applet {

    static final int WIDTH = 200;
    static final int HEIGHT = 200;

    ImageComponent2D buffer;

    public SimpleOffScreenTest() {
        createOffScreenImage();
    }

    public void paint(Graphics g) {
        g.drawImage(buffer.getImage(), 0, 0, this);
    }

    void createOffScreenImage() {
        Canvas3D c = getOffScreenCanvas();

        SimpleUniverse u = new SimpleUniverse(c);
        u.getViewingPlatform().setNominalViewingTransform();
        BranchGroup bg = createSceneGraph();
        u.addBranchGraph(bg);

        createBufferImage();
        c.setOffScreenBuffer(buffer);
        c.renderOffScreenBuffer();
        c.waitForOffScreenRendering();
    }

    Canvas3D getOffScreenCanvas() {
        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D c = new Canvas3D(config, true);
        Screen3D scr = c.getScreen3D();
        scr.setSize(new Dimension(1280, 1024));
        scr.setPhysicalScreenWidth(0.36124);
        scr.setPhysicalScreenHeight(0.28899555);
        return c;
    }

    void createBufferImage() {
        BufferedImage offScreenImg = new BufferedImage(WIDTH, WIDTH ,
                                               BufferedImage.TYPE_INT_ARGB);
        buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, offScreenImg);
        buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);
    }

    BranchGroup createSceneGraph() {
        BranchGroup objRoot = new BranchGroup();
        objRoot.addChild(new ColorCube(0.4));
        return objRoot;
    }

    public static void main(String argv[]) {
        new MainFrame(new SimpleOffScreenTest(), WIDTH, HEIGHT);
    }
}

Reply via email to