Why does the Slider value change from an Integer to a Real, causing the Manipulate expression to break?
It seems like a bug. Here's fix, via explicitly constructing the slider (Manipulator
):
n =.;
DynamicModule[{c, t, main, f},
Manipulate[
ControlActive[{x, y}, main[x, y]],
{{x, c/2, "n1"}, 1, y - c, 1},
{{y, n - c/2, "n2"}, x + c, n, 1, Manipulator[#1, {x + c, n, 1}] &},
SynchronousUpdating -> False,
Initialization :> (
n = 300;
c = 100;
main[x_, y_] := main[x, y] = f[x, y];)]]
This isolates, or at least localizes the problem to having a Dynamic
lower limit to the slider; the argument x + c
automatically has Dynamic[]
applied to it by Manipulate
to make the slider limits dynamically dependent on x
and c
:
n =.;
DynamicModule[{c, t, main, f},
Manipulate[
ControlActive[{x, y}, main[x, y]],
{{x, c/2, "n1"}, 1, y - c, 1},
{{y, n - c/2, "n2"}, x + c, n, 1, Manipulator[#1, {Dynamic[x + c], n, 1}] &},
SynchronousUpdating -> False,
Initialization :> (
n = 300;
c = 100;
main[x_, y_] := main[x, y] = f[x, y];)]]
Further isolation:
n = 300;
DynamicModule[{y = 200, c = 100, x = 50}, (* fails with Dynamic 1st argument *)
{Manipulator[Dynamic[y], {Dynamic[x + c], n, 1}], Dynamic@y}
]
DynamicModule[{y = 200, c = 100, x = 50}, (* works with no Dynamic argument *)
{Manipulator[Dynamic[y], {x + c, n, 1}], Dynamic@y}
]
DynamicModule[{y = 200, c = 100, x = 50}, (* works with Dynamic 2nd argument *)
{Manipulator[Dynamic[y], {x + c, Dynamic@n, 1}], Dynamic@y}
]