From 51f8fa18eb65a3a95a163bef71fcfffb49063be6 Mon Sep 17 00:00:00 2001 From: Julian Ibarz Date: Fri, 23 Nov 2012 20:30:13 -0800 Subject: j3dcore: avoid null pointer when reading raster depth-only from Canvas3d Taken from java3d issue 593: When I'm reading the z-buffer with a Raster, a NullPointerException occurs (in fact, two). This is because the image raster is accessed whereas is not initialized, and also because we send the depthComp to the native readRaster function instead of the real buffer (i named it depthBuffer). Also the destination offset is send to the native readRaster function instead of source offset. I made a very light patch that corrects this bugs. Signed-off-by: Julian Ibarz Signed-off-by: Harvey Harrison --- .../share/javax/media/j3d/GraphicsContext3D.java | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/classes/share') diff --git a/src/classes/share/javax/media/j3d/GraphicsContext3D.java b/src/classes/share/javax/media/j3d/GraphicsContext3D.java index f37686d..b0919eb 100644 --- a/src/classes/share/javax/media/j3d/GraphicsContext3D.java +++ b/src/classes/share/javax/media/j3d/GraphicsContext3D.java @@ -2332,20 +2332,33 @@ public class GraphicsContext3D extends Object { canvas3d.makeCtxCurrent(); canvas3d.syncRender(canvas3d.ctx, true); Point rasterSrcOffset = new Point(); - ras.getDstOffset(rasterSrcOffset); + ras.getSrcOffset(rasterSrcOffset); DepthComponentRetained depthComp = ras.depthComponent; int depthType = 0; + Object depthBuffer = null; if(depthComp != null) { depthType = depthComp.type; + depthBuffer = (depthType == DepthComponentRetained.DEPTH_COMPONENT_TYPE_FLOAT) ? floatBuffer : intBuffer; } + + int imageDataType = 0; + int imageFormatType = 0; + Object imageBuffer = null; + + if ( (ras.type & Raster.RASTER_COLOR) != 0) { + imageDataType = image.getImageDataTypeIntValue(); + imageFormatType = image.getImageFormatTypeIntValue(false); + imageBuffer = image.imageData.get(); + } + Pipeline.getPipeline().readRaster(canvas3d.ctx, ras.type, rasterSrcOffset.x, rasterSrcOffset.y, rasterSize.width, rasterSize.height, canvasSize.height, - image.getImageDataTypeIntValue(), - image.getImageFormatTypeIntValue(false), - image.imageData.get(), - depthType, depthComp); + imageDataType, + imageFormatType, + imageBuffer, + depthType, depthBuffer); canvas3d.drawingSurfaceObject.unLock(); } -- cgit v1.2.3