What's wrong with this code?

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 18 19:30:37 PDT 2015


This crashes when triggered:

		voxel_vec [string] move_buttons = [
			"button_xp" : voxel_vec ([ 1, 0, 0 ]),
			"button_xm" : voxel_vec ([ -1, 0, 0 ]),
			"button_yp" : voxel_vec ([ 0, 1, 0 ]),
			"button_ym" : voxel_vec ([ 0, -1, 0 ]),
			"button_zp" : voxel_vec ([ 0, 0, 1 ]),
			"button_zm" : voxel_vec ([ 0, 0, -1 ]) ];

		foreach (bname, vec; move_buttons) {
			Button bmove = cast (Button) g.getObject (bname);
			bmove.addOnClicked (delegate void (Button aux) {
				if (!glw.sel_active) return;
				
				glw.vf.move (3, vec, glw.sel_limits);
				glw.set_mesh (glw.vf.polygonize);
			} );
		}

I get:

First-chance exception at 0x754fc42d in 3dprinterapp.exe: 
0xE0440001: 0xe0440001.
Unhandled exception at 0x754fc42d in 3dprinterapp.exe: 
0xE0440001: 0xe0440001.

Inspection with the debugger reveals the var glw is "out of 
scope" at the location of the if (!glw... and single stepping 
past that line triggers the exception. The variable glw is in 
scope however, this code just above it works:

		b.addOnValueChanged (delegate void (SpinButton aux) {
			for (int i = 0; i < 6; i++)
				sellimits [i] = selwidgets [i].getValueAsInt ();

			glw.set_sel_box (sellimits);
			glw.sel_active = 1;
			glw.actual_queue_draw ();
		});

(works)

Could this be a compiler bug? I have no idea what could be wrong. 
Bringing it out of the loop produces the same error:

		Button xmove = cast (Button) g.getObject ("button_xp");
		xmove.addOnClicked (delegate void (Button aux) {
			if (!glw.sel_active) return;
			glw.vf.move (3, voxel_vec ([ 1, 0, 0 ]), glw.sel_limits);
			glw.set_mesh (glw.vf.polygonize);
		});

(same error)

This is with DMD 2.067.1 under Windows, I'm stuck with it because 
if I upgrade to 2.068 then GtkD doesn't work anymore. Also using 
GtkD 3.0.0, version 3.1.4 doesn't work with either version of DMD.

Thanks in advance for any help.


More information about the Digitalmars-d-learn mailing list