2-Way Slider jassert (solved)

I’m trying to use a bunch of 2 Way Sliders and continually get this exception. I’m unsure how to work around it. I get that I need to override/bypass it somehow with a function that gets the min and max values instead but how is that accomplished?

double getValue() const
    {
        // for a two-value style slider, you should use the getMinValue() and getMaxValue()
        // methods to get the two values.
        jassert (style != TwoValueHorizontal && style != TwoValueVertical);

        return currentValue.getValue();
    }

If you call getValue() on a TwoValue slider, what result would you expect?
That’s why you should call getMinValue() and getMaxValue() instead (just like the comment above the jassert suggests)

HTH

Sorry I can’t have explained well enough, I get that, but my code is stopped by the above jassert from getValue() everytime I hover over a slider. I want to know how to stop the assert from occurring seeing as I can’t override getValue(), the only option I can see at the moment is commenting out the jassert which obviously isn’t an option :slight_smile:

I don’t have an issue of getting the values from min and max I just want my code to run without the assertion.

Can you tell us, what method calls the getValue() method? Or in other words: what’s between mouse over and that assertion? :slight_smile:

It’s just a standard Slider with in[id]->setSliderStyle(Slider::TwoValueHorizontal); set. There’s nothing fancy going on at all. The slider is calling getValue() as soon as the mouse moves into it’s clip region. I feel like I must be missing some flag that needs setting or something?

You should be able to debug, which method is calling getValue(), that’s important for us to figure out, whats the reason behind that. When the assertion is triggered, you can look at the call stack and kind of zoom out to see why the method is even called.

I’ve made it as simple as possible with the following code:

Constructor:

test.setSliderStyle(Slider::TwoValueHorizontal);
		test.setRange(0.0f, 1.0f, 0.001f);
		test.setMinAndMaxValues(0.0f, 1.0f);
		addAndMakeVisible(test);

Member:

Slider test;

resize:

test.setBounds(0, 0, 200, 20);

exception:

  •   this	0x0000016f8b239850 {owner={onValueChange=empty onDragStart=empty onDragEnd=empty ...} style=TwoValueHorizontal (9) ...}	juce::Slider::Pimpl *
    

Thanks for trying to help :slight_smile:

Can’t reproduce this behavior, neither with master nor the develop branch, sorry. It’s working just fine.

As I mentioned before, you should look at the call stack while debugging, to see which method is calling getValue(). Maybe you have a custom LookAndFeel, which is calling it? Or any other modifications?
Without that info I am afraid, we can’t help you with it.

In case you don’t know about call stack here two screenshots I took in XCode as an example.
Here you can see, who is calling the setRange() method, by clicking the caller one level below in the call stack (left).

1 Like

You are my new hero! Better Debugging was on my to learn list. I always wondered why the callstack was empty when I looked, and now I know it only relates to breakpoints, thanks very much for pointing it out to me. It really is a revelation.

I found the problem immediately which was a custom timer that gets a slider value for an information display regardless of Slider style (until now).

Very old thread but I’m finding this occurs whenever I programmatically call setMinValue/setMaxValue on a TwoWay Slider.

Stack trace:

#0 0x00000001035adce8 in juce::Slider::Pimpl::getValue at /JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:196
#1 0x00000001036c2ab4 in juce::Slider::Pimpl::updatePopupDisplay()::‘lambda’()::operator()() const at /JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:1103
#2 0x00000001036c290c in juce::Slider::Pimpl::updatePopupDisplay at /JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:1087
#3 0x00000001035ae760 in juce::Slider::Pimpl::setMinValue at /JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:269
#4 0x00000001035ae440 in juce::Slider::setMinValue at /JUCE/modules/juce_gui_basics/widgets/juce_Slider.cpp:1609

It seems like whenever setMin or setMaxValue is called programmatically, updatePopupDisplay is called. Since there’s no sliderBeingDragged active, the popup display’s text method tries getValue, which fires this assert.

Relevant snippet from updatePopupDisplay:

        const auto valueToShow = [this]
        {
            constexpr SliderStyle multiSliderStyles[] { SliderStyle::TwoValueHorizontal,
                                                        SliderStyle::TwoValueVertical,
                                                        SliderStyle::ThreeValueHorizontal,
                                                        SliderStyle::ThreeValueVertical };

            if (std::find (std::begin (multiSliderStyles), std::end (multiSliderStyles), style) == std::end (multiSliderStyles))
                return getValue();

            if (sliderBeingDragged == 2)
                return getMaxValue();

            if (sliderBeingDragged == 1)
                return getMinValue();

            return getValue();
        }();

Not totally sure what to do here. It doesn’t look like there’s anyway to manually set sliderBeingDragged - and even if so, I kind of would’ve expected setMin or setMax to handle this for me. I’m just going to comment out the assert since I don’t really care in this case (it’s updating a string with no relevance since it’s not being shown) but that’s not really a true solution.

Seems like setMin and setMax should either set sliderBeingDragged temporarily (kind of silly) or updatePopupDisplay should take a parameter which signifies the reason it was triggered (sliderBeingDragged in most cases, but not always).

What is style when it is calling getValue()? I assume it is not one of those constants? But why not, if it is a TwoWay Slider? Is there another constant that is needed there? Or is perhaps style not being set as expected?