IllegalArgumentException: height (0) cannot be 0 or less

edited October 2013 in Programming Questions

I am using processing from within an Eclipse RCP application. The Applet is initialized as follow:

            public final class ChartComposite<T extends  PApplet> extends Composite {
                    private final T pApplet;
                    private final Frame frame;

                    public ChartComposite(T aPApplet,Composite parent,int style) {
                        super(parent,style|SWT.EMBEDDED);
                        pApplet = aPApplet;
                        setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
                        frame = SWT_AWT.new_Frame(this);
                        frame.setLayout(new BorderLayout());
                            frame.add(pApplet, BorderLayout.CENTER);
                        pApplet.init();
                    }


                    public void dispose() {
                        pApplet.stop();
                        pApplet.dispose();
                        super.dispose();
                    }
                }

When the frame is resized to have a height of 0, I get the exception, eg.:

Exception in thread "Animation Thread" java.lang.IllegalArgumentException: Width (1216) and height (0) cannot be <= 0 at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source) at sun.awt.Win32GraphicsConfig.createCompatibleImage(Unknown Source) at processing.core.PGraphicsJava2D.allocate(PGraphicsJava2D.java:201) at processing.core.PGraphicsJava2D.setSize(PGraphicsJava2D.java:135) at processing.core.PApplet.resizeRenderer(PApplet.java:1576) at processing.core.PApplet.run(PApplet.java:2170) at java.lang.Thread.run(Unknown Source)

I am trying to detect when the frame has a height of 0, to prevent the resizing, but this seems to be quite a mission. Any suggestions on how to stop the exception from happening?

Answers

  • My guess is that when you do pApplet.init(), the frame where you added the PApplet isn't rendered yet, ie. the SWT hasn't set it a size (and position) yet.
    So its dimensions are zero and PApplet takes these dimensions to define the size of its rendering, which is rejected.

    Perhaps you can delay the call to init() to a stage when the frame is rendered.

Sign In or Register to comment.