Xamarin ios timespan axis freezes on iphone 4

Oystein Bjorke 4 years ago • updated by Simon Taylor 3 years ago 1
This discussion was imported from CodePlex

lanks wrote at 2014-03-20 05:43:

I have created a timespan axis graph that is the same as the example in the oxyplot monotouch examples app.

When the app goes to load the graph is freezes when running on an iphone 4. I have tested this with an iphone 5 and it runs perfectly. There is no error reported in the application output in xamarin studio. The app just completely freezes.

This also happens with the oxyplot monotouch examples app when selecting the timespan axis graph.

Any ideas why this is happening?

Liam

benhysell wrote at 2014-03-20 15:48:

Liam,

Can you run instruments against your iPhone 4 and see where your app is spending all of its time?

-ben

lanks wrote at 2014-03-21 02:09:

Hi Ben

Thanks for your response.

I ran instruments with the time profiler but I am not too sure what I am looking for? Here is a link to the data from instruments https://www.dropbox.com/s/gahj6l53bl4dbnx/SportsEdgeInstruments.trace.zip

Are you able to confirm that you can run the timespan axis with an iPhone < 5?

Cheers
Liam

benhysell wrote at 2014-03-21 12:58:

Liam,

I cannot confirm running on less than 5s and iPad 3...but my app does have an x-axis that is a date axis...I'm about to release a new version of code with OxyPlot in it. Thus if there is a major issue with the 4 I'm concerned.

Basically with Instruments I'm looking for where all the time is being spent. From your snapshot start at the top and keep hitting down arrows until the function that is using up all of the time is exposed.

Although I can't see exactly where the code is falling down, I can at least point you in the correct direction. From your Instruments after I clicked down through all of the calls:

Image

TimeSpan axis correct? OxyPlot/Axes/TimeSpanAxis.cs line 173
protected override double CalculateActualInterval(double availableSize, double maxIntervalSize)
From Instruments it looks like the line 188 is just spinning
double nextInterval = goodIntervals.FirstOrDefault(i => i > interval);
I'd start poking around here with the debugger and see why that FirstOrDefault is never ending, or why it is being called so many times
CodePlex
I ran into this one on iPhone 5.

In OxyPlot.Axes.DateTimeAxis.CalculateActualInterval() there is the code below. The check
Math.Abs(nextInterval) < double.Epsilon
was failing if nextInterval was zero, so the loop never terminated. Changing it to the following fixed the problem. Something not quite right with Xamarin here.
nextInterval == 0 || Math.Abs(nextInterval) < double.Epsilon


            var goodIntervals = new[]
                                    {
                                        Second, 2 * Second, 5 * Second, 10 *
Second, 30 * Second, Minute, 2 * Minute,
                                        5 * Minute, 10 * Minute, 30 * Minute,
Hour, 4 * Hour, 8 * Hour, 12 * Hour, Day,
                                        2 * Day, 5 * Day, Week, 2 * Week,
Month, 2 * Month, 3 * Month, 4 * Month,
                                        6 * Month, Year
                                    };

            double interval = goodIntervals[0];

            int maxNumberOfIntervals = Math.Max((int)(availableSize /
maxIntervalSize), 2);

            while (true)
            {
                if (range / interval < maxNumberOfIntervals)
                {
                    break;
                }

                double nextInterval = goodIntervals.FirstOrDefault(i => i >
interval);
                if (Math.Abs(nextInterval) < double.Epsilon)
                {
                    nextInterval = interval * 2;
                }

                interval = nextInterval;
            }