resizeCanvas should update dimensions

Hello!



I'm working with JME and its canvas toolkit.

It seems that SimpleCanvasImpl and SimplePassCanvasImpl don't update their size variables with resizeCanvas is called.



protected int width, height;



These are set in the constructor


    protected SimpleCanvasImpl(int width, int height) {
        this.width = width;
        this.height = height;
    }



but when calling JMECanvasImplementor method


    public void resizeCanvas(int width, int height) {
        final int fWidth = width <= 0 ? 1 : width;
        final int fHeight = height <= 0 ? 1 : height;
        Callable<?> exe = new Callable<Object>() {
            public Object call() {
                if (renderer != null)
                    renderer.reinit(fWidth, fHeight);
                return null;
            }
        };
        GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).enqueue(exe);
    }


they don't get updated.

I've fixed implementing my custom resize method on SimpleCanvasImpl derived class but i think JMECanvasImplementor should be changed as follows:


    public void resizeCanvas(int width, int height)
    {
        final int fWidth = width <= 0 ? 1 : width;
        final int fHeight = height <= 0 ? 1 : height;
        Callable<?> exe = new Callable<Object>() {
            public Object call() {
                if (renderer != null)
                    renderer.reinit(fWidth, fHeight);
                return null;
            }
        };
        GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).enqueue(exe);
        this.width = fWidth;
        this.height = fHeight;
    }



Hope this is ok :)

Good catch, thank you! Two suggestions though:


  • Please post a patch in Contribution Depot. If you don't want to commit it yourself, I'm sure somebody else will do that for you.

  • I think it is more correct to place the assignment of the new values to the width and height fields inside the Callable's call(), just after the renderer has actually been reinited. Otherwise it would still be possible to get incorrect values when calling their getters.

I made the best experience with using the code of RenParticleEditor.java as a base, because resizing works flawlessly on there.