2

In our Windows 10 UWP app we are suffering from Heap corruption during random page navigations. The timing and location is always different yet the same result is there, Heap corruption when Native debugging is turned on and an immediate crash when it's turned off.

Below is the callstack at the time of the heap corruption with as much info as we've been able to gather from Visual Studio.

ntdll.dll!_RtlReportCriticalFailure@8()
ntdll.dll!_RtlpHeapHandleError@4()
ntdll.dll!_RtlpLogHeapFailure@24()
ntdll.dll!RtlSizeHeap()
Windows.UI.Xaml.dll!XcpAllocation::OSMemoryFree(void * pAddress=0x0b4164f0)
Windows.UI.Xaml.dll!ctl::SupportErrorInfo::`scalar deleting destructor'(unsigned int)
Windows.UI.Xaml.dll!ctl::ComBase::OnFinalRelease()
Windows.UI.Xaml.dll!ctl::ComBase::ReleaseImpl()
Windows.UI.Xaml.dll!DirectUI::UIAffinityReleaseQueue::DoCleanup(unsigned char bSync='\0', unsigned char * pbCompleted=0x058ff5af)
Windows.UI.Xaml.dll!DirectUI::UIAffinityReleaseQueue::BuildTree(unsigned char * returnValue=0x058ff5f2)
Windows.UI.Xaml.dll!DirectUI::BuildTreeService::BuildTrees(bool * pWorkLeft=0x058ff62b)
Windows.UI.Xaml.dll!AgCoreCallbacks::FrameworkCallbacks_PhasedWorkDistributor_PerformWork(unsigned int * pWorkleft=0x058ff6a4)
Windows.UI.Xaml.dll!CCoreServices::NWDrawTree(HWWalk * pHWWalk=0x0082cab8, ICoreRenderTarget * pIRenderTarget=0x008fb444, VisualTree * pVisualTree=0x00886668, unsigned int forceRedraw=0, XRECT_WH * prcDirtyRect=0x058ff7f8)
Windows.UI.Xaml.dll!CCoreServices::NWDrawMainTree(ICoreRenderTarget * pIRenderTarget=0x008fb444, bool fForceRedraw=false, XRECT_WH * prcDirtyRect=0x058ff7f8)
Windows.UI.Xaml.dll!CWindowRenderTarget::Draw(CCoreServices * pCore=0x008f2ea0, unsigned int fForceRedraw=0, XRECT_WH * prcDirtyRect=0x058ff7f8)
Windows.UI.Xaml.dll!CXcpBrowserHost::OnTick()
Windows.UI.Xaml.dll!CXcpDispatcher::Tick()
Windows.UI.Xaml.dll!CXcpDispatcher::OnReentrancyProtectedWindowMessage(HWND__ * msg=1026, unsigned int lParam=0, unsigned int hr=0x058ff41c, long reentrancyGuard)
Windows.UI.Xaml.dll!CXcpDispatcher::WindowProc(HWND__ * hwnd=0x001906aa, unsigned int msg=1026, unsigned int wParam=0, long lParam=0)
user32.dll!__InternalCallWinProc@20()
user32.dll!UserCallWinProcCheckWow()
user32.dll!DispatchMessageWorker()
user32.dll!_DispatchMessageW@4()
Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessMessage(int bDrainQueue=1, int * pbAnyMessages=0x00000000)
Windows.UI.dll!Windows::UI::Core::CDispatcher::WaitAndProcessMessages(void * hEventWait=0x00000000)
Windows.UI.dll!Windows::UI::Core::CDispatcher::ProcessEvents(Windows::UI::Core::CoreProcessEventsOption options=CoreProcessEventsOption_ProcessUntilQuit)
Windows.UI.Xaml.dll!CJupiterWindow::RunCoreWindowMessageLoop()
Windows.UI.Xaml.dll!CJupiterControl::RunMessageLoop()
Windows.UI.Xaml.dll!DirectUI::DXamlCore::RunMessageLoop()
Windows.UI.Xaml.dll!DirectUI::FrameworkView::Run()
twinapi.appcore.dll!Windows::ApplicationModel::Core::CoreApplicationView::Run(void)
twinapi.appcore.dll!Microsoft::WRL::Details::Make<struct Microsoft::WRL::Details::InvokeHelper<struct Windows::Foundation::IAsyncActionCompletedHandler,class <lambda_e4b1934750ab38adfb74f12296e81f29>,2>,class <lambda_e4b1934750ab38adfb74f12296e81f29> &>(class <lambda_e4b1934750ab38adfb74f12296e81f29> &)
SHCore.dll!CallerIdentity::GetCallingProcessHandle(unsigned long,enum RUNTIMEBROKER_CALLERIDENTITY_CHECK,void * *)
kernel32.dll!@BaseThreadInitThunk@12()
ntdll.dll!__RtlUserThreadStart()
ntdll.dll!__RtlUserThreadStart@8()

Any chance anyone has encountered this exact, or close to issue and managed to resolve it? Thanks in advance.

EDIT! Got some new info! sadly no fix yet but progress... :)

Turns out the issue is caused by the VisualStateGroups used to create an adaptive interface seen below:

<Style TargetType="controls:CollectionView">
    <Setter Property="RelativePanel.AlignLeftWithPanel" Value="True"/>
    <Setter Property="RelativePanel.AlignRightWithPanel" Value="True"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="controls:CollectionView">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <GridView x:Name="List" 
                              Grid.Row="1" 
                              BorderBrush="Black" 
                              ItemsSource="{TemplateBinding ItemsSource}"
                              ItemTemplate="{TemplateBinding ItemTemplate}"
                              SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem, Mode=TwoWay}"
                              ShowsScrollingPlaceholders="False"
                              Background="Transparent"
                              RelativePanel.AlignLeftWithPanel="True"
                              RelativePanel.AlignRightWithPanel="True">
                    </GridView>

                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup>
                            <VisualState x:Name="UnSelectable">
                                <VisualState.StateTriggers>
                                    **<StateTrigger IsActive="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsNotSelectable}"/>**
                                </VisualState.StateTriggers>

                                <VisualState.Setters>
                                    <Setter Target="List.Background" Value="#AAAAAA"/>
                                    <Setter Target="List.IsHitTestVisible" Value="False"/>
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

if i disable the above statetrigger the app will not crash, sadly i need the logic inside this state... any work arounds possible or an explanation what i am doing wrong?

  • Usually we don't use style like this. What do you want to achieve in your view? – Grace Feng Feb 04 '16 at 09:39
  • I am trying to adjust the background color of the GridView based upon the setting of the IsSelectable property added on the control in a Page. Mostly i am wondering why using a binding to set the value of a StateTrigger would cause heap corruption. The setup i am using should not be that strange if you ask me... Any feedback or work around would be welcome :) – Mike Overwater Feb 05 '16 at 08:13
  • @GraceFeng-MSFT So there's no way to provide a StateTrigger with its value using a Binding in a MVVM structured app? – Mike Overwater Feb 09 '16 at 15:10
  • So, you mean you have a `GridView` in your page, each item has the property 'IsSelectable'? And you want to change the `Background` color of each item of `GridView` according to the `IsSelectable` property? Sorry for late responding, I didn't see it. – Grace Feng Feb 10 '16 at 08:09
  • @GraceFeng-MSFT The CollectionView has the IsSelectable property hence the binding to the TemplateParent (CollectionView) which in its StateSetters manipulates the GridView. But yes that is indeed what i am trying to achieve, the actual goal is to modify the Background of the items inside the GridView but this was my first step – Mike Overwater Feb 10 '16 at 10:05
  • So is this "CollectionView" your usercontrol? Did you tried to use `ItemContainerStyleSelector` or `ItemTemplateSelector` of the `GridView` for your case? [Here in the answer](http://stackoverflow.com/questions/34709608/itemscontrol-comma-separated-values-in-uwp-app/34717848#34717848) is another case using `ItemTemplateSelector`. – Grace Feng Feb 15 '16 at 01:35
  • hehe yeah it is custom made by me so it's probably not the best. I forgot all about the ItemContainerStyleSelector.... I suppose that would suffice for my use case. Only downside would be the fact i need to duplicate most DataTemplates as ItemTemplates. 1 for IsSelectable and one for the false state. – Mike Overwater Feb 15 '16 at 08:44
  • For your scenario `ItemContainerStyleSelector` should solve this problem, try it and if you have new problem with it, you can ask a new question. Thank you! – Grace Feng Feb 15 '16 at 08:52
  • dont forget to place an answer so i can mark it ;) thanks for sticking with me and the constant support – Mike Overwater Feb 15 '16 at 09:39

1 Answers1

0

For your scenario, ItemContainerStyleSelector may solve the problem, or you can use ItemTemplateSelector to design two different Datatemplate for your GridView.

Here is a sample in the answer uses ItemTemplateSelector for ItemsControl.

Community
  • 1
  • 1
Grace Feng
  • 16,564
  • 2
  • 22
  • 45