Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random 'cannot access disposed object' when using custom loaded image #3857

Closed
huoyaoyuan opened this issue Dec 24, 2020 · 4 comments
Closed
Labels
area-Images Images, SVG team-Rendering Issue for the Rendering team

Comments

@huoyaoyuan
Copy link

Describe the bug

I'm using BitmapSource.SetSourceAsync to load images, because the loading requires authorizing so that cannot be achieved by UriSource.

The image is used in a virtualized GridView.

Loading code snippet:

                if (request is null)
                {
                    image.Source = null;
                    loadingProgress.IsActive = false;
                    copyCommand.NotifyCanExecuteChanged();
                    return;
                }

                var bitmap = new BitmapImage();
                image.Source = bitmap; // the Image control inside the user control
                loadingProgress.IsActive = true; // a ProgressRing
                copyCommand.NotifyCanExecuteChanged();

                try
                {
                    // performing the load
                    var entry = await _imageCache.GetImageAsync(request, refreshMemoryCache).ConfigureAwait(true);

                    var stream = entry.GetWinRTStream();

                    if (image.Source == bitmap) // if the control has been reused for virtualization, discard it
                    {
                        _currentEntry = entry;
                        loadingProgress.IsActive = false;
                        copyCommand.NotifyCanExecuteChanged();

                        await bitmap.SetSourceAsync(stream);
                    }
                }
                catch
                {
                    if (image.Source == bitmap)
                        loadingProgress.IsActive = false;
                }

Throwing call stack:

 	KernelBase.dll!RaiseFailFastException�()	未知
>	combase.dll!RoFailFastWithErrorContextInternal2(HRESULT hrError, unsigned long cStowedExceptions, _STOWED_EXCEPTION_INFORMATION_V2 * * aStowedExceptionPointers) 行 1455	C++
 	CoreMessagingXP.dll!Microsoft::System::DispatcherQueue::DeferInvokeCallback(void *)	未知
 	CoreMessagingXP.dll!CFlat::SehSafe::Execute<<lambda_a81ff790741c2a62f2197c2561f5fe49>>()	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::ActionCallback::ImportAdapter$(class CFlat::Box$1<struct CFlat::FunctionPointerAndUserData$1<long (*)(void *)> > *)	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::Messaging::MessageSession::Callback_InvokeDeferInvoke(class Microsoft::CoreUI::ActionCallback *,struct System::UIntPtr)	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::DeferredCall::Callback_Dispatch(void)	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::DeferredCallDispatcher::Callback_OnDispatch(void)	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::Dispatcher::Callback_DispatchNextItem(void)	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::EventLoop::Callback_RunCoreLoop(enum Microsoft::CoreUI::Dispatch::RunMode)	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::SystemCoreMessaging::Callback_OnGroupDispatch(enum Microsoft::CoreUI::Dispatch::SystemCoreMessaging$GroupPriority,struct CFlat::Ref<struct System::IntPtr>)	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::SystemCoreMessaging::NoContext_GroupDispatchHandler(enum Microsoft::CoreUI::Dispatch::SystemCoreMessaging$GroupPriority,void *)	未知
 	CoreMessagingXP.dll!Microsoft::CoreUI::Dispatch::SystemCoreMessaging::NoContext_NormalPriorityDispatchHandler(void *)	未知
 	CoreMessaging.dll!Microsoft__CoreUI__DispatchGroupHandler$CallbackThunk(class System::Delegate *)	未知
 	CoreMessaging.dll!Microsoft::CoreUI::DispatchGroupHandler::Invoke()	未知
 	CoreMessaging.dll!Microsoft::CoreUI::Dispatch::EventLoop::Callback_RunCoreLoop()	未知
 	CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter::OnUserDispatch()	未知
 	CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter_DoWork()	未知
 	CoreMessaging.dll!Microsoft::CoreUI::Dispatch::UserAdapter_WindowProc()	未知
 	user32.dll!UserCallWinProcCheckWow()	未知
 	user32.dll!DispatchMessageWorker()	未知
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::ProcessEvents() 行 1161	C++
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::StartDesktop() 行 210	C++
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplicationFactory::Start(ABI::Microsoft::UI::Xaml::IApplicationInitializationCallback * pCallback) 行 713	C++
 	[托管到本机的转换]	
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationStatics.Microsoft.UI.Xaml.IApplicationStatics.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback)	未知
 	Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback)	未知

I cannot find anything useful here.

If the application is launched with debugger, the exception will be ignored. One image control which seems triggers the exception will be empty.

If the application is launched without debugger, it will crash.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Dec 24, 2020
@huoyaoyuan
Copy link
Author

huoyaoyuan commented Dec 24, 2020

Looks like a duplicate of microsoft/CsWinRT#640

Maybe not. The exception call stack is totally native. No managed exception incurred here.

Edit:
Confirmed that the CsWinRT fix doesn't resolve this issue. This is another one.

@ranjeshj ranjeshj added area-Images Images, SVG team-Rendering Issue for the Rendering team labels Jan 6, 2021
@huoyaoyuan
Copy link
Author

huoyaoyuan commented Jan 20, 2021

Further information:

If I change the call to synchronized SetSource AND change the backing stream to WinRT InMemoryRandomAccessStream, the issue seems to disappear.

Projected .NET stream with SetSource will get a deadlock in UI thread.

It seems to be caused by the source stream containing corrupt image. (NOT confirmed - seems wrong)

@huoyaoyuan
Copy link
Author

Whether .NET or WinRT stream passed into it can cause different exceptions. This indicates a CsWinRT issue. Moving to them.

@huoyaoyuan
Copy link
Author

No longer reproduces when updating to latest CsWinRT.

@ghost ghost removed the needs-triage Issue needs to be triaged by the area owners label Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Images Images, SVG team-Rendering Issue for the Rendering team
Projects
None yet
Development

No branches or pull requests

2 participants