Hi! I was trying to get an image of the rendered frame and an unexpected
exception happened ......

The code is:

/***************/
/***************/
/***************/
/*
 * AgentGUI_01.java
 *
 * Created on November 22, 2002, 12:11 PM
 */

package Proj898.EnvVisualizerAgent;

import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.*;
import java.util.*;
import javax.vecmath.*;
import javax.media.j3d.PositionInterpolator;
import java.awt.*;
import java.awt.geom.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.image.codec.jpeg.*;


/**
 *
 * @author  rir785
 */

class CapturingCanvas3D extends Canvas3D  {

    public boolean writeJPEG_;
    private int postSwapCount_;

    public CapturingCanvas3D(GraphicsConfiguration gc) {
        super(gc);
        postSwapCount_ = 0;
    }

    public void postSwap() {
        if(writeJPEG_) {
            System.out.println("Writing JPEG");
            GraphicsContext3D  ctx = getGraphicsContext3D();
            // The raster components need all be set!
            Raster ras = new Raster(
                   new Point3f(-1.0f,-1.0f,-1.0f),
                   Raster.RASTER_COLOR,
                   0,0,
                   512,512,
                   new ImageComponent2D(
                             ImageComponent.FORMAT_RGB,
                             new BufferedImage(256,256,

BufferedImage.TYPE_INT_RGB)),
                   null);

            ctx.readRaster(ras);

            // Now strip out the image info
            BufferedImage img = ras.getImage().getImage();

            // write that to disk....
            try {
                FileOutputStream out = new
FileOutputStream("c:\\Capture"+postSwapCount_+".jpg");
                JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder(out);
                JPEGEncodeParam param =
encoder.getDefaultJPEGEncodeParam(img);
                param.setQuality(0.9f,false); // 90% qualith JPEG
                encoder.setJPEGEncodeParam(param);
                encoder.encode(img);
                writeJPEG_ = false;
                out.close();
            } catch ( IOException e ) {
                System.out.println("I/O exception!");
            }
            postSwapCount_++;
        }
    }
}

public class AgentGUI_01 extends javax.swing.JFrame {
    javax.media.j3d.BoundingSphere bounds=new
javax.media.j3d.BoundingSphere(new
javax.vecmath.Point3d(0.0,0.0,0.0),Float.MAX_VALUE);
    BranchGroup scene =new BranchGroup();
    CapturingCanvas3D canvas3d_C=null;
    /** Creates new form AgentGUI_01 */
    public AgentGUI_01() {
        initComponents();
        /*********************/
        java.awt.GraphicsConfiguration
config=com.sun.j3d.utils.universe.SimpleUniverse.getPreferredConfigurati
on();
        //javax.media.j3d.Canvas3D canvas3d=new
javax.media.j3d.Canvas3D(config);
        canvas3d_C=new CapturingCanvas3D(config);
        jPanel3D.add("Center",canvas3d_C);
        /******************************************/
        scene.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
        scene.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
        scene.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
        //SimpleUniverse is a Convenience Utility class
        SimpleUniverse simpleU =new SimpleUniverse(canvas3d_C);
        /******************************************/
        TransformGroup vpTrans = null;
        vpTrans =
simpleU.getViewingPlatform().getViewPlatformTransform();
        Vector3f translate=new Vector3f(0.0f,2.0f,2.5f);
        Transform3D T3D=new Transform3D();
        T3D.setTranslation(translate); // set as translation
        T3D.setRotation(new
javax.vecmath.AxisAngle4f(1.0f,0.0f,0.0f,(float)((2*Math.PI)-(Math.PI/7.
0))));
        vpTrans.setTransform(T3D); // used for initial position
        com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior
keyNavBeh = new
com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior(vpTrans);
        keyNavBeh.setSchedulingBounds(bounds);
        /******************************************/
        scene.addChild(keyNavBeh);
        /******************************************/
        //scene.addChild(new VisualObject());
        scene.addChild(new ColorCube());
        /******************************************/
        scene.compile();
        //This moves the ViewPlatform back a bit so the
        //objects in the scene can be viewed.
        //simpleU.getViewingPlatform().setNominalViewingTransform();
        //simpleU.getViewingPlatform().getViewPlatformTransform();
        simpleU.addBranchGraph(scene);
        /*********************/
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jPanel3D = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jButtonCaptureImage = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanelRenderedImage = new javax.swing.JPanel();

        getContentPane().setLayout(new
org.netbeans.lib.awtextra.AbsoluteLayout());

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });


jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("GUI for Agent (With Canvas3D)");
        getContentPane().add(jLabel1, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, 284, 400, -1));

        jPanel3D.setLayout(new java.awt.BorderLayout());

        jPanel3D.setBorder(new
javax.swing.border.TitledBorder("Canvas3D"));
        getContentPane().add(jPanel3D, new
org.netbeans.lib.awtextra.AbsoluteConstraints(81, 0, 319, 284));

        jPanel2.setLayout(new
org.netbeans.lib.awtextra.AbsoluteLayout());

        jButtonCaptureImage.setText("Image");
        jButtonCaptureImage.addMouseListener(new
java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonCaptureImageMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButtonCaptureImageMouseReleased(evt);
            }
        });

        jPanel2.add(jButtonCaptureImage, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 80, -1));


jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("\"Name\"");
        jPanel2.add(jLabel2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, 270, 80, -1));

        getContentPane().add(jPanel2, new
org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, 284));

        jPanelRenderedImage.setBorder(new
javax.swing.border.TitledBorder("Rendered Image"));
        getContentPane().add(jPanelRenderedImage, new
org.netbeans.lib.awtextra.AbsoluteConstraints(80, 300, 150, 140));

        pack();
    }

    private void
jButtonCaptureImageMouseReleased(java.awt.event.MouseEvent evt) {
        canvas3d_C.writeJPEG_ = true;
        canvas3d_C.repaint();
    }

    private void
jButtonCaptureImageMousePressed(java.awt.event.MouseEvent evt) {
        // Add your handling code here:

    }

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new AgentGUI_01().show();
    }


    // Variables declaration - do not modify
    private javax.swing.JPanel jPanel3D;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanelRenderedImage;
    private javax.swing.JButton jButtonCaptureImage;
    // End of variables declaration

}
/***************/
/***************/
/***************/



When I push the jbutton, the output is:

Writing JPEG
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x10007181
Function=[Unknown.]
Library=C:\j2sdk1.4.1\jre\bin\J3D.dll
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 javax.media.j3d.GraphicsContext3D.readRasterNative(Native
Method)
        at
javax.media.j3d.GraphicsContext3D.doReadRaster(GraphicsContext3D.java:23
06)
        at
javax.media.j3d.GraphicsContext3D.readRaster(GraphicsContext3D.java:2211
)
        at
Proj898.EnvVisualizerAgent.CapturingCanvas3D.postSwap(AgentGUI_01.java:6
0)
        at javax.media.j3d.Renderer.doWork(Renderer.java:266)
        at javax.media.j3d.J3dThread.run(J3dThread.java:250)
Dynamic libraries:
0x00400000 - 0x00406000         C:\j2sdk1.4.1\jre\bin\java.exe
0x77F80000 - 0x77FFB000         C:\WINNT\System32\ntdll.dll
0x77DB0000 - 0x77E0B000         C:\WINNT\system32\ADVAPI32.dll
0x77E80000 - 0x77F31000         C:\WINNT\system32\KERNEL32.dll
0x77D30000 - 0x77DA1000         C:\WINNT\system32\RPCRT4.dll
0x78000000 - 0x78046000         C:\WINNT\system32\MSVCRT.dll
0x6D330000 - 0x6D45C000         C:\j2sdk1.4.1\jre\bin\client\jvm.dll
0x77E10000 - 0x77E6F000         C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F79000         C:\WINNT\system32\GDI32.dll
0x77570000 - 0x775A0000         C:\WINNT\System32\WINMM.dll
0x6D1D0000 - 0x6D1D7000         C:\j2sdk1.4.1\jre\bin\hpi.dll
0x6D300000 - 0x6D30D000         C:\j2sdk1.4.1\jre\bin\verify.dll
0x6D210000 - 0x6D229000         C:\j2sdk1.4.1\jre\bin\java.dll
0x6D320000 - 0x6D32D000         C:\j2sdk1.4.1\jre\bin\zip.dll
0x6D000000 - 0x6D0FA000         C:\j2sdk1.4.1\jre\bin\awt.dll
0x77800000 - 0x7781E000         C:\WINNT\System32\WINSPOOL.DRV
0x76620000 - 0x76630000         C:\WINNT\system32\MPR.DLL
0x75E60000 - 0x75E7A000         C:\WINNT\System32\IMM32.dll
0x77A50000 - 0x77B45000         C:\WINNT\system32\ole32.dll
0x6D180000 - 0x6D1D0000         C:\j2sdk1.4.1\jre\bin\fontmanager.dll
0x51000000 - 0x51076000         C:\WINNT\System32\ddraw.dll
0x728A0000 - 0x728A6000         C:\WINNT\System32\DCIMAN32.dll
0x71C10000 - 0x71CC4000         C:\WINNT\System32\D3DIM.DLL
0x60000000 - 0x60045000         C:\WINNT\System32\MSCTF.dll
0x10000000 - 0x10057000         C:\j2sdk1.4.1\jre\bin\J3D.dll
0x0D0E0000 - 0x0D206000         C:\WINNT\System32\d3d8.dll
0x0D210000 - 0x0D215000         C:\WINNT\System32\d3d8thk.dll
0x77820000 - 0x77827000         C:\WINNT\system32\VERSION.dll
0x759B0000 - 0x759B6000         C:\WINNT\system32\LZ32.DLL
0x71710000 - 0x71794000         C:\WINNT\system32\COMCTL32.dll
0x6D230000 - 0x6D235000         C:\j2sdk1.4.1\jre\bin\jawt.dll
0x69000000 - 0x69125000         C:\WINNT\System32\atioglaa.dll
0x0D860000 - 0x0D898000         C:\WINNT\System32\D3DREF8.DLL
0x779B0000 - 0x77A4B000         C:\WINNT\system32\OLEAUT32.DLL
0x77920000 - 0x77943000         C:\WINNT\system32\imagehlp.dll
0x72A00000 - 0x72A2D000         C:\WINNT\system32\DBGHELP.dll
0x13440000 - 0x1344B000         C:\WINNT\System32\PSAPI.DLL
Local Time = Fri Nov 22 21:12:13 2002
Elapsed Time = 9
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.1-b21 mixed mode)
#
# An error report file has been saved as hs_err_pid1032.log.
# Please refer to the file for further information.
#

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to