Problem when a polygon has not been draw completely, then call roiManager("add");

I want to draw a roi and add to roiManager:

Macro:

waitForUser("draw roi, then click me");
// then draw a polygon
roiManager("add");
run("Measure");

When I draw a polygon roi, sometimes at the end the double click does not work well and the roi has not been closed, then I confirm the dialogue, then the roi was added. It seems that the roi is an broken roi, because the measured results is also strange:

Area:	0.000 (sometimes is 0.097, very small number)
Mean:    NaN	
Min:    1974	(I do not konw why the min is not 0)
Max:   0

Is there a command to check if the roi is unfinished polygon?
Thanks.

solved


// check if roi is not drawn
	type = selectionType(); //print(type);
	if (type == -1){
		// forget to select
		// the smart way to deal with while loop in a Macro: just branch again and again, untill collapse in one shot
		waitForUser("warning: you need to draw a polygon! retry!");
		cropAndShedMaskOutSaveImageAndRoi(aFileName);
		return 0;
	}

// measure area, also check if polygon roi is broken
    run("Measure");
    updateResults();
	 // check if polygon roi is not closed
	aTemp = getResult("Mean",nResults-1);//print(aTemp);
	if (isNaN(aTemp)){
		waitForUser("warning: polygon roi is not closed yet! retry!");
		cropAndShedMaskOutSaveImageAndRoi(aFileName);
		return 0;
	}