Main Site Documentation

Very slow touch response in one screen and possible bug found


#1

I have an issue with one of the screens I have created. The response from touch is very slow. It I press the button and hold my finger on it, I get a response after about 5 to 10 seconds. This is repeatable on this screen. A very simple one with a few edit boxes and some buttons (17 items in total) All the other screens work fine, even the main screen with 56 items.

If I let the screen timeout and return to the previous screen, it works fine. This one screen does this all the time.

My programme works by creating the screens as I need them. I dispose of the previous screen before creating the new one. This all works and I have 7 screen in total. 6 work perfect but this one does not. Here is the XML for it.

<Glide Version="1.0.5">
  <Window Name="sensorWindow" Width="480" Height="272" BackColor="F0F0A0">
    <Button Name="cancelButton" X="392" Y="222" Width="80" Height="42" Alpha="255" Text="Cancel" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
    <TextBlock Name="titleText" X="0" Y="0" Width="480" Height="24" Alpha="255" Text="System Settings - Sensor 1" TextAlign="Center" TextVerticalAlign="Top" Font="4" FontColor="0" BackColor="A0A0A0" ShowBackColor="True"/>
    <Button Name="acceptButton" X="8" Y="222" Width="80" Height="42" Alpha="255" Text="Accept" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
    <TextBlock Name="instance88135" X="2" Y="30" Width="60" Height="32" Alpha="255" Text="Range" TextAlign="Left" TextVerticalAlign="Middle" Font="3" FontColor="0" BackColor="000000" ShowBackColor="False"/>
    <TextBox Name="rangeText" X="60" Y="30" Width="80" Height="32" Alpha="255" Text="0.0" TextAlign="Right" Font="4" FontColor="000000"/>
    <TextBlock Name="instance90695" X="2" Y="70" Width="60" Height="32" Alpha="255" Text="Offset" TextAlign="Left" TextVerticalAlign="Middle" Font="3" FontColor="0" BackColor="000000" ShowBackColor="False"/>
    <TextBox Name="offsetText" X="60" Y="70" Width="80" Height="32" Alpha="255" Text="0.0" TextAlign="Right" Font="4" FontColor="000000"/>
    <TextBlock Name="instance91288" X="142" Y="30" Width="50" Height="32" Alpha="255" Text="M" TextAlign="Left" TextVerticalAlign="Middle" Font="4" FontColor="0" BackColor="000000" ShowBackColor="False"/>
    <TextBlock Name="instance93062" X="142" Y="70" Width="50" Height="32" Alpha="255" Text="M" TextAlign="Left" TextVerticalAlign="Middle" Font="4" FontColor="0" BackColor="000000" ShowBackColor="False"/>
    <Button Name="nextButton" X="390" Y="40" Width="80" Height="32" Alpha="255" Text="Next" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
    <Button Name="prevButton" X="390" Y="100" Width="80" Height="32" Alpha="255" Text="Previous" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
    <TextBox Name="changeHeightText" X="219" Y="173" Width="80" Height="32" Alpha="255" Text="" TextAlign="Left" Font="4" FontColor="000000"/>
    <TextBlock Name="instance32108" X="117" Y="173" Width="100" Height="32" Alpha="255" Text="Change Height" TextAlign="Left" TextVerticalAlign="Middle" Font="2" FontColor="0" BackColor="000000" ShowBackColor="False"/>
    <TextBlock Name="instance32581" X="303" Y="172" Width="70" Height="32" Alpha="255" Text="meters" TextAlign="Left" TextVerticalAlign="Middle" Font="4" FontColor="0" BackColor="000000" ShowBackColor="False"/>
    <TextBox Name="tankCount" X="219" Y="132" Width="80" Height="32" Alpha="255" Text="" TextAlign="Left" Font="4" FontColor="000000"/>
    <TextBlock Name="instance1058" X="117" Y="132" Width="90" Height="32" Alpha="255" Text="Tank Count" TextAlign="Left" TextVerticalAlign="Middle" Font="2" FontColor="0" BackColor="000000" ShowBackColor="False"/>
    <Button Name="captureButton" X="169" Y="70" Width="80" Height="32" Alpha="255" Text="Capture" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
  </Window>
</Glide>

This is running on a Sytech Designs Nova board (sorry, I needed the 200Mhz processing speed for my design).

What would cause the SLOW RESPONSE to touch? I have some background threads running for serial and ADC handling but they are also running when the other screens are visible.

CODE ERROR?
In trying to track this down, I found what appears to be a bug in the dispose method of the window in DisplayObjectContainer.cs

The original code would leave objects un-deleted due to the way it actually performs the for loop when I call Dispose on the window. The _displayList gets smaller as it deletes the children and therefore leaves a few behind. I have changed the code to the one below and it disposes of all the children from the last to the first instead.

        
public override void Dispose()
        {
            DisplayObject child;
            int Count;

            Count = _displayList.Count;

            for (int i = (Count - 1); i >= 0; i--)
            {
                child = (DisplayObject)_displayList[i];
                child.Dispose();
                RemoveChild(child);
            }

            Graphics.Dispose();
        }


#2

You are right, original code is wrong, but why so complicated fix? It is as simple as this:



        public override void Dispose()
        {
            foreach (var child in _displayList)
                ((DisplayObject) child).Dispose();
            _displayList.Clear();

            Graphics.Dispose();
        }


It will be also faster, since RemoveChild tests first if the child is in _displayList, which in this case is pure waste of cpu time.


#3

Nice work. I am coming from a C/C++ background and didn’t know yet about foreach()

:slight_smile:

Thanks for the effort though.


#4

My point was that it is not necessary to remove items from list one by one in the loop and even check if they are in the list, foreach is just syntactical sugar.