xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.42k stars 507 forks source link

UIPrintPageRenderer hangs app after iPhone update #20730

Closed jamesingreersc closed 1 week ago

jamesingreersc commented 2 weeks ago

Steps to Reproduce

Not sure if to open this here or with Apple(or both)

  1. Update iPhone to 17.5.1 - NOTE: Worked perfectly with iOS 17.4 <
  2. Attempt to create a PDF using UIPrintPageRenderer

Expected Behavior

PDF created

Actual Behavior

iOS application completely hangs up trying to get NumberOfPages from renderer

Environment

iOS .Net 8 using VS 17.10.2

Version information ``` Microsoft Visual Studio Community 2022 Version 17.10.2 VisualStudio.17.Release/17.10.2+35004.147 Microsoft .NET Framework Version 4.8.09032 Installed Version: Community Visual C++ 2022 00482-90000-00000-AA601 Microsoft Visual C++ 2022 ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASA Service Provider 1.0 ASP.NET and Web Tools 17.10.341.11210 ASP.NET and Web Tools Azure App Service Tools v3.0.0 17.10.341.11210 Azure App Service Tools v3.0.0 Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 17.10.341.11210 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio C# Tools 4.10.0-3.24303.7+bef690dda43733707d7dccea9868fe51f34eb8a0 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Extensibility Message Bus 1.4.39 (main@e8108eb) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. GitHub Copilot 0.2.889.30432 GitHub Copilot is an AI pair programmer that helps you write code faster and with less work. Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Mono Debugging for Visual Studio 17.10.8 (a565b86) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 6.10.1 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Razor (ASP.NET Core) 17.10.3.2427201+4f57d1de251e654812adde201c0265a8ca7ca31d Provides languages services for ASP.NET Core Razor. SQL Server Data Tools 17.10.172.0 Microsoft SQL Server Data Tools Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory. Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory. ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript Tools 17.0.30327.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 4.10.0-3.24303.7+bef690dda43733707d7dccea9868fe51f34eb8a0 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual C++ for Cross Platform Mobile Development (Android) 15.0.35004.147 Visual C++ for Cross Platform Mobile Development (Android) Visual F# Tools 17.10.0-beta.24228.1+dd749058c91585e9b5dae62b0f8df892429ee28f Microsoft Visual F# Tools Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio. VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info Xamarin 17.10.0.110 (main@cf2e960) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 17.10.3.10 (remotes/origin/d17-10@3beef58f89) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 17.9.0 (38e87ba) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14) Xamarin.Android Reference Assemblies and MSBuild support. Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d Xamarin.iOS and Xamarin.Mac SDK 16.4.0.23 (9defd91b3) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Build Logs

There is no hint in the logs at all. App just stops and stops output.

Example Project (If Possible)

I don't have an example project. This is our production app.

Code is pretty simple, render.NumberOfPages is the hang up line

 var render = new UIPrintPageRenderer();

   if (webViewPages != null && reportIndex < webViewPages.Length)
   {
       render.AddPrintFormatter(
          webViewPages[reportIndex].ViewPrintFormatter,
          0);
   }
   else
   {
       render.AddPrintFormatter(
            new UIMarkupTextPrintFormatter(reportContent),
            0);
   }

          var printable = CoreGraphics.CGRectExtensions.Inset(page, 0, 0);
          render.SetValueForKey(NSValue.FromCGRect(page), new NSString("paperRect"));
          render.SetValueForKey(NSValue.FromCGRect(printable), new NSString("printableRect"));

          var pdfData = new NSMutableData();
          UIGraphics.BeginPDFContext(pdfData, page, null);

          int pageNum = 0;
          for (pageNum = 0; pageNum < render.NumberOfPages; pageNum++)
          {
              UIGraphics.BeginPDFPage();
              var bounds = UIGraphics.PDFContextBounds;
              render.DrawPage(pageNum, bounds);
          }

 UIGraphics.EndPDFContext();
rolfbjarne commented 1 week ago

Code is pretty simple, render.NumberOfPages is the hang up line

I created a test app based on this, and it works fine for me, so we'll need a complete test project we can use to reproduce this in order to investigate further.

microsoft-github-policy-service[bot] commented 1 week ago

Hi @jamesingreersc. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

jamesingreersc commented 1 week ago

@rolfbjarne I finally figured it out. Must be something in the new ios 17.5.1 update. But the gist was that we are using a UIView to select multiple reports to generate and email. I had to create the pdf's before that window got called and just figure which one's they selected to email. Apparently now that renderer is still being used from the selection controller even though it had been closed. The accepted answer in this link pointed me in the right direction. He was having a crash but pretty much same thing was happening.

https://developer.apple.com/forums/thread/718398