# Strange double evaluation using MorphologicalGraph

(MMA 9.0.0 on Mac OS/X 10.8)

Please consider the following snippet (this is as SMALL as I could make it -- my attempts at making a smaller repro-case eliminated the effect that I am investigating)

Manipulate[
With[{img =
Image@RandomVariate[
NormalDistribution[0.5 + p - p, 0.25], {25, 25}]},
With[{grf =
(* comment the following line to stop
the double-evaluation *)
MorphologicalGraph@
ColorNegate@
Image@
WatershedComponents@
Binarize@
img},
GraphicsGrid[{{img, grf}}]
]],
(* click the + on the controller, wait a second,
and you will see double-evaluation *)
{p, 1, 10, 1,
Appearance -> "Open"}]


In the interactive block that results, press the + and - keys to advance or retract the value of p. If you are patient, on each press of + or -, after a delay of 1 second or so, the entire display will evaluate a second time. This behavior is rather obvious and jarring since the generated image and graph are random.

If you remove the call of MorphologicalGraph, the behavior does not happen. Somehow, MorphologicalGraph seems to be (hypothetically) causing an extra evaluation step after a 'settling time'.

I'd like to at least understand this behavior if not get rid of it.

-
I think this is an attempt of Manipulate to first calculate the result quickly, then calculate it accurately, thus having both responsiveness and accuracy. It's related to options such as PerformanceGoal and ControlActive but I can't find how to turn it off right now. Hope this info will help you search for the solution. Then there's also BlockRandom and SeedRandom for getting reproducible results from Random* functions. –  Szabolcs Feb 15 '13 at 16:20
See this too please: mathematica.stackexchange.com/questions/8373/… –  Szabolcs Feb 15 '13 at 16:23
I'm not sure if this is a bug or not. Here's a more minimal test case: Manipulate[Column[{Pause[0.2]; x, $PerformanceGoal,$ControlActiveSetting}], {x, 0, 1}, ContinuousAction -> False]. ContinuousAction -> False fixes double evaluation when dragging the slider, but not when clicking the +/- buttons. The behaviour is the same in 8. –  Szabolcs Feb 15 '13 at 16:32
This seems to be fixed as of V10.0.0. –  Michael E2 Aug 8 at 20:08