[Android] RadGridView with too many rows crashes app

2 Answers 38 Views
DataGrid
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
Jérôme asked on 14 Mar 2024, 10:20 AM | edited on 14 Mar 2024, 10:20 AM

Hi,

Using VS 2022 17.10 / .NET 8.0.3 / Telerik UI for MAUI 6.8 / MAUI 8.0.10 / Android 10 (API 29)

I've got a RadGridView on a ContentPage :


 <c:NDCDataGrid
     x:Name="dataGridDetails"
     ItemsSource="{Binding DetailedData}">
     <t:RadDataGrid.Columns>
         <t:DataGridTextColumn HeaderText="Location" PropertyName="LocationName" />
         <t:DataGridTextColumn
             CellContentFormat="{}{0: dd/MM/yyyy}"
             HeaderText="Date"
             PropertyName="Date" />
         <t:DataGridTextColumn HeaderText="Count" PropertyName="Count" />
         <t:DataGridTextColumn HeaderText="Type" PropertyName="Desc" />
     </t:RadDataGrid.Columns>
 </c:NDCDataGrid>

 

My NDCDataGrid is defined like this :

 

<t:RadDataGrid
    x:Class="NDC.Mobile.Controls.NDCDataGrid"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:t="http://schemas.telerik.com/2022/xaml/maui"
    AutoGenerateColumns="False"
    CanUserReorderColumns="False"
    SelectionMode="Single"
    SelectionUnit="Row"
    UserFilterMode="Disabled">
    <t:RadDataGrid.AlternateRowBackgroundStyle>
        <AppThemeBinding>
            <AppThemeBinding.Light>
                <t:DataGridBorderStyle
                    BackgroundColor="Beige"
                    BorderColor="Black"
                    BorderThickness="1" />
            </AppThemeBinding.Light>
            <AppThemeBinding.Dark>
                <t:DataGridBorderStyle
                    BackgroundColor="DimGray"
                    BorderColor="White"
                    BorderThickness="1" />
            </AppThemeBinding.Dark>
        </AppThemeBinding>
    </t:RadDataGrid.AlternateRowBackgroundStyle>
    <t:RadDataGrid.SelectionStyle>
        <AppThemeBinding>
            <AppThemeBinding.Light>
                <t:DataGridBorderStyle
                    BackgroundColor="LightGreen"
                    BorderColor="Black"
                    BorderThickness="1" />
            </AppThemeBinding.Light>
            <AppThemeBinding.Dark>
                <t:DataGridBorderStyle
                    BackgroundColor="DarkBlue"
                    BorderColor="White"
                    BorderThickness="1" />
            </AppThemeBinding.Dark>
        </AppThemeBinding>
    </t:RadDataGrid.SelectionStyle>
</t:RadDataGrid>

 

When loading a list of 900+ elements, the app crashes 


await Task.Run(async () =>
{
    DetailedData = new ObservableCollection<MyType>(await myService.Method());
});

 

MyType is defined like this :


   public int LocationName { get; set; }

   public int Count { get; set; }

   public DateTime Date { get; set; }

   public string Desc { get; set; }

 

Java.Lang.RuntimeException: 'Canvas: trying to draw too large(119964240bytes) bitmap.'

 

 	0xFFFFFFFFFFFFFFFF in Android.Runtime.RuntimeNativeMethods.monodroid_debugger_unhandled_exception	C#
 	0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:13,5	C#
 	0x1E in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:126,26	C#
 	0x17 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw	C#
 	0x8C in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:20830,5	C#
 	0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6	C#
 	0xA6 in Android.Graphics.RecordingCanvas.DrawBitmap at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Graphics.RecordingCanvas.cs:161,5	C#
 	0x68 in SkiaSharp.Views.Android.SurfaceFactory.DrawSurface	C#
 	0xCB in SkiaSharp.Views.Android.SKCanvasView.OnDraw	C#
 	0x11 in Android.Views.View.n_OnDraw_Landroid_graphics_Canvas_ at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.View.cs:18998,4	C#
 	0x9 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:125,5	C#
 	0xF in Java.Interop.JniNativeMethods.CallNonvirtualBooleanMethodA at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:18200,4	C#
 	0x73 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualBooleanMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:20458,4	C#
 	0x8A in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualBooleanMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:164,7	C#
 	0x70 in Android.Views.ViewGroup.DrawChild at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:2839,5	C#
 	0x4 in Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutRenderer.DrawChild at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellFlyoutRenderer.cs:172,4	C#
 	0x1C in Android.Views.ViewGroup.n_DrawChild_Landroid_graphics_Canvas_Landroid_view_View_J at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.ViewGroup.cs:2824,4	C#
 	0xD in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLJ_Z at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:323,5	C#

The control is unusable in this state !

Thanks.

Yana
Telerik team
commented on 14 Mar 2024, 03:19 PM

Hello Jérôme,

Thank you for sending the code snippets.

I've recreated the scenario in a sample app, still, I am not able to reproduce the reported crash. I've attached my test app, can you please download it and test it on your side? Do you reproduce the issue with it? If not, can you modify it with any additional code that I am missing, so that the crash can be seen and sent it back for further research?

I look forward to your reply.

Regards,
Yana
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
commented on 14 Mar 2024, 03:59 PM

Hi Yana,

Thank you for your answer. I adjusted your project in order to replicate the issue.

It seems the problem comes from my BaseContentPage that all my ContentPage inherit from.

Any help is appreciated.

Jérôme

2 Answers, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 15 Mar 2024, 06:30 AM

Hi Jérôme,

Thank you for modifying the app.

The problem is related to the ScrollView used inside the BaseContentPage, let me explain in more details - DataGrid is a virtualized control ( such as ListView, for example) and as such it requires its parent container to provide the space to fall into, meaning the parent container should provide the size.  ScrollView, on the other hand, relies on its children to measure themselves.

So, when you place the DataGrid inside ScrollView, its virtualization (items recycling) is broken, and since it has so many items, it raises the error indicating it just cannot handle drawing the canvas. 

In addition, DataGrid provides its own scrolling mechanism and it's not recommended placing it inside a scrolling container.  The best approach is to place it inside a Grid with "*" size. 

You can also take  a look at the .NET MAU ScrollView Docs, where this is explicitly stated:

ScrollView objects should not be nested. In addition, ScrollView objects should not be nested with other controls that provide scrolling, such as CollectionView, ListView, and WebView.

I remain at your disposal if you have any additional questions on this.

0
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
answered on 15 Mar 2024, 07:45 AM

Hi Yana,

Thank you for this detailed explanation. I guess the only solution is to remove the ScrollView from the BaseContentPage, and put explicitly on all child views that need it. Unless there is another solution ?

Jérôme

Yana
Telerik team
commented on 15 Mar 2024, 08:46 AM

Hi Jérôme,

Indeed, I am afraid the only solution is to remove the ScrollView from the BaseContentPage - there isn't a way to make it work otherwise. 

I understand this will cause additional rework of the other pages, still,  in this way the DataGrid virtualization mechanism will enable you to load that amount of items without a problem.

Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
commented on 15 Mar 2024, 08:50 AM

Thank you for your answer Yana !
Tags
DataGrid
Asked by
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Yana
Telerik team
Jérôme
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or