Thread overview | |||||
---|---|---|---|---|---|
|
March 16, 2014 Memory errors | ||||
---|---|---|---|---|
| ||||
When using both simpleimage and DWT my program crashes with "core.exception.InvalidMemoryOperationError" after I show an image in a GUI window and then close the window. I'm presumably misunderstanding something about how the windows deal with memory deallocation, but this happens even when copying tutorial examples. e.g. module main; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.graphics.all; void main () { auto display = new Display; auto shell = new Shell; shell.setText("Title"); Label label = new Label (shell, SWT.BORDER); label.setBounds(shell.getClientArea()); Image image = new Image(display, "C:/dev/data/tree.png"); label.setImage(image); shell.pack(); shell.open(); while (!shell.isDisposed) if (!display.readAndDispatch()) display.sleep(); display.dispose(); } This successfully creates the display and shows an image, but when I close the window the memory error exception is thrown. If I run the same code without creating the image then there's no errors. If I create the image without setting it on the label I still get the error. Any ideas? |
March 16, 2014 Re: Memory errors | ||||
---|---|---|---|---|
| ||||
Posted in reply to PhilE | Ah, I need to dispose of the image before disposing of the display.
On Sunday, 16 March 2014 at 19:33:09 UTC, PhilE wrote:
> When using both simpleimage and DWT my program crashes with "core.exception.InvalidMemoryOperationError" after I show an image in a GUI window and then close the window. I'm presumably misunderstanding something about how the windows deal with memory deallocation, but this happens even when copying tutorial examples.
>
> e.g.
>
> module main;
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.graphics.all;
>
> void main ()
> {
> auto display = new Display;
> auto shell = new Shell;
>
> shell.setText("Title");
>
> Label label = new Label (shell, SWT.BORDER);
> label.setBounds(shell.getClientArea());
>
> Image image = new Image(display, "C:/dev/data/tree.png");
> label.setImage(image);
>
> shell.pack();
> shell.open();
>
> while (!shell.isDisposed)
> if (!display.readAndDispatch())
> display.sleep();
>
> display.dispose();
> }
>
> This successfully creates the display and shows an image, but when I close the window the memory error exception is thrown. If I run the same code without creating the image then there's no errors. If I create the image without setting it on the label I still get the error. Any ideas?
|
March 16, 2014 Re: Memory errors | ||||
---|---|---|---|---|
| ||||
Posted in reply to PhilE | On 3/16/14, PhilE <theotherphil@hotmail.com> wrote:
> When using both simpleimage and DWT my program crashes with "core.exception.InvalidMemoryOperationError"
It's likely something is trying to allocate in a destructor.
|
Copyright © 1999-2021 by the D Language Foundation