2-Way Slider jassert (solved)


#1

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();
    }

#2

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


#3

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.


#4

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


#5

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?


#6

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.


#7

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:


#8

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.


#9

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).


#10

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).