cocopon / tweakpane

:control_knobs: Compact GUI for fine-tuning parameters and monitoring value changes
https://tweakpane.github.io/docs/
MIT License
3.57k stars 90 forks source link

Cannot read properties of undefined (reading 'valueController') #582

Closed bolopenguin closed 10 months ago

bolopenguin commented 10 months ago

Hello, I have some problems to dinamically update the sliders min and max values.

Working on "tweakpane": "^4.0.1".

I was updating the values as described in this previous issue.

In particular this is my simplified code:

let minValue = -10;
let maxValue = 10;
const stc = sliderInputs.controller_.valueController;
const sc_props = stc.sc_.sliderProps;
sc_props.set("minValue", minValue);
sc_props.set("maxValue", maxValue);

The values are not being updated, and I get the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'valueController')
    at updateBboxFolder (Gui.svelte:262:49)
    at SliderBladeApi.<anonymous> (Gui.svelte:334:9)
    at Object.handler (tweakpane.js:7424:13)
    at tweakpane.js:154:22
    at Array.forEach (<anonymous>)
    at Emitter.emit (tweakpane.js:153:19)
    at Object.handler (tweakpane.js:7394:27)
    at tweakpane.js:154:22
    at Array.forEach (<anonymous>)
    at Emitter.emit (tweakpane.js:153:19) 

There is a new updated way to do this? Perhaps without using private attributes? Thank you in advance for your support.

bolopenguin commented 10 months ago

Update

I fixed in this way:

let minValue = -10;
let maxValue = 10;
const stc = sliderInputs.controller.valueController;
const sc = stc.sliderC_.props.valMap_;
sc.min.value_ = minValue;
sc.max.value_ = maxValue;

But I keep using private methods...

cocopon commented 10 months ago

Tweakpane v4 creates SliderInputBindingApi for slider inputs, so you can access its min and max directly:

const pane = new Pane();
const i = pane.addBinding(params, 'foo', {
  min: 0,
  max: 1,
});

i.min = -100;
i.max = 100;

API: https://tweakpane.github.io/docs/api/classes/SliderInputBindingApi.html

bolopenguin commented 10 months ago

That solved my issue. Thank you so much for the fast answer.

Fixed previous code:

let minValue = -10;
let maxValue = 10;
sliderInputs.min = minValue;
sliderInputs.max = maxValue;