microsoft / CsWinRT

C# language projection for the Windows Runtime
MIT License
539 stars 102 forks source link

PdfDocument spawns zombie process #1249

Open neelabo opened 2 years ago

neelabo commented 2 years ago

Describe the bug

When I use PdfDocument in WPF, the process remains even after closing the app.

To Reproduce

Expected behavior

App should be terminated normally

Version Info

Additional context

Below is the reproducible code.

    public partial class App : Application
    {
        private async void Application_Startup(object sender, StartupEventArgs e)
        {
            await GetPdfPageStream(@"sample.pdf", 0);
            GC.Collect();
            this.Shutdown();
        }

        private static async Task<MemoryStream> GetPdfPageStream(string path, uint index)
        {
            using var pdfStream = File.OpenRead(path);
            using var winrtStream = pdfStream.AsRandomAccessStream();
            var pdfDocument = await PdfDocument.LoadFromStreamAsync(winrtStream);
            using var pdfPage = pdfDocument.GetPage((uint)index);
            var ms = new MemoryStream();
            var outStream = ms.AsRandomAccessStream();
            await pdfPage.RenderToStreamAsync(outStream);
            ms.Seek(0, SeekOrigin.Begin);
            return ms;
        }
    }
Marv51 commented 2 years ago

See also: https://stackoverflow.com/questions/50930684/wpf-app-not-exiting-because-of-uwp-pdfdocument

neelabo commented 2 years ago

Added the graphics driver version to the post. AMD's latest version of the driver.

neelabo commented 2 years ago

The debug run appeared to complete successfully, but actually ended with an error. The program '[23248] PdfTest.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.