Main Site Documentation

CLR_E_DIVIDE_BY_ZERO exception using Slider


#1

Trying to load a Glide UI that uses a Slider control (vertical, if it makes a difference), and I’m getting a CLR_E_DIVIDE_BY_ZERO exception when loading the window, unless I remove the slider. Here’s the slider markup:


<Slider Name="speed" X="287" Y="34" Width="20" Height="200" Alpha="255" Direction="vertical" SnapInterval="10" TickInterval="10" TickColor="000000" KnobSize="20" Minimum="0" Maximum="100" Value="0"/>

and here’s the exception details:

#### Exception System.Exception - CLR_E_DIVIDE_BY_ZERO (1) ####
#### Message: 
#### GHIElectronics.NETMF.Glide.UI.Slider::Init [IP: 00c5] ####
#### GHIElectronics.NETMF.Glide.UI.Slider::set_KnobSize [IP: 000a] ####
#### GHIElectronics.NETMF.Glide.UI.Slider::.ctor [IP: 005a] ####
#### GHIElectronics.NETMF.Glide.GlideLoader::LoadSlider [IP: 00fb] ####
#### GHIElectronics.NETMF.Glide.GlideLoader::GetComponent [IP: 00ad] ####
#### GHIElectronics.NETMF.Glide.GlideLoader::LoadWindow [IP: 00a9] ####
#### GHIElectronics.NETMF.Glide.GlideLoader::LoadWindow [IP: 000b] ####

Suggestions for troubleshooting?


#2

Here is Init method code from codeplex:


        private void Init()
        {
            if (_direction == SliderDirection.Horizontal)
            {
                _knob = new Rectangle(0, 0, _knobSize, (int)((double)Height / 1.2));
                _lineSize = Width - _knobSize;
            }
            else
            {
                _knob = new Rectangle(0, 0, (int)((double)Width / 1.2), _knobSize);
                _lineSize = Height - _knobSize;
            }

            if (_tickInterval < 0)
                _tickInterval = 0;
            else if (_tickInterval > _lineSize)
                _tickInterval = _lineSize;

            if (_tickInterval > 0)
                _tickSize = (double)_lineSize / TickInterval;
            else
                _tickSize = (double)_lineSize / _lineSize;

            if (_snapInterval < 0)
                _snapInterval = 0;
            else if (_snapInterval > _lineSize)
                _snapInterval = _lineSize;

            if (_snapInterval > 0)
                _snapSize = (double)_lineSize / _snapInterval;
            else
                _snapSize = (double)_lineSize / _lineSize;

            if (_max > 0)
                _pixelsPerValue = _lineSize / (_max - _min);
        }


#3

@ Architect

Perfect!

Width and KnobSize were the same, which made _lineSize 0, thus the DivideByZero exception. All sorted now…

THANKS! :slight_smile:


#4

You are welcome! ;D