I made the error of calling gui.remember(obj);
and gui.add(obj, 'x');
in the wrong order.
So this is the solution:
var obj = { x: 5 };
var gui = new dat.GUI();
gui.remember(obj);
gui.add(obj, 'x');
What happens is that dat.gui makes an internal map of objects to be remembered when calling the gui.add()
function. This map, gui.__rememberedObjectIndecesToControllers[]
, is used in the internal getCurrentPreset()
function when saving values.
However it will only add object to this map if they have been stored in gui.__rememberedObjects[]
which is why the order is so important.
The reason the minified version threw an error is that when it tried to get the mapped value from gui.__rememberedObjectIndecesToControllers[]
, it tries to loop over an undefined
value.
The sample on http://workshop.chromeexperiments.com/examples/gui/#5--Saving-Values actually shows this proper order, I just overlooked it:
var fizzyText = new FizzyText();
var gui = new dat.GUI();
gui.remember(fizzyText);
// Add controllers ...