canvasIdAlloc = false;
    public void setOffScreenBuffer(ImageComponent2D buffer) {	int width, height;        if (!offScreen)            throw new IllegalStateException(J3dI18N.getString("Canvas3D1"));        if (offScreenRendering)            throw new RestrictedAccessException(J3dI18N.getString("Canvas3D2"));	// Check that offScreenBufferPending is not already set	J3dDebug.doAssert(!offScreenBufferPending, "!offScreenBufferPending");               if (offScreenBuffer != null && offScreenBuffer != buffer) {            ImageComponent2DRetained i2dRetained =                     (ImageComponent2DRetained)offScreenBuffer.retained;                        i2dRetained.setUsedByOffScreen(false);        }	if (buffer != null) {	    ImageComponent2DRetained bufferRetained =		(ImageComponent2DRetained)buffer.retained;	    if (bufferRetained.byReference &&		!(bufferRetained.getRefImage(0) instanceof BufferedImage)) {		throw new IllegalArgumentException(J3dI18N.getString("Canvas3D15"));	    }	    if (bufferRetained.getNumberOfComponents() < 3 ) {		throw new IllegalArgumentException(J3dI18N.getString("Canvas3D16"));	    }            if (buffer.isLive()) {                throw new IllegalSharingException(J3dI18N.getString("Canvas3D26"));            }            if (bufferRetained.getInImmCtx()) {                throw new IllegalSharingException(J3dI18N.getString("Canvas3D27"));            }            if (buffer != offScreenBuffer && bufferRetained.getUsedByOffScreen()) {                throw new IllegalSharingException(J3dI18N.getString("Canvas3D28"));            }            bufferRetained.setUsedByOffScreen(true);	    width = bufferRetained.width;	    height = bufferRetained.height;            // Issues 347, 348 - assign a canvasId for off-screen Canvas3D            if (manualRendering) {                if (canvasBit == 0) {                    canvasId = VirtualUniverse.mc.getCanvasId();                    canvasBit = 1 << canvasId;                }            }        }	else {	    width = height = 0;            // Issues 347, 348 - release canvasId for off-screen Canvas3D            if (manualRendering) {                if (canvasBit != 0) {                    VirtualUniverse.mc.freeCanvasId(canvasId);                    canvasBit = 0;                    canvasId = 0;                }            }        }	if ((offScreenCanvasSize.width != width) ||	    (offScreenCanvasSize.height != height)) {	    if (drawable != null) {		// Fix for Issue 18 and Issue 175		// Will do destroyOffScreenBuffer in the Renderer thread. 		sendDestroyCtxAndOffScreenBuffer();		drawable = null;	    }            // set the canvas dimension according to the buffer dimension	    offScreenCanvasSize.setSize(width, height);	    this.setSize(offScreenCanvasSize);	    if (width > 0 && height > 0) {		sendCreateOffScreenBuffer();	    }	    ctx = null; 	}	else if (ctx != null) {            removeCtx();	}        offScreenBuffer = buffer;        synchronized(dirtyMaskLock) {            cvDirtyMask[0] |= MOVED_OR_RESIZED_DIRTY;            cvDirtyMask[1] |= MOVED_OR_RESIZED_DIRTY;        }    }