Crash when saving a large number (>5k) of PNG files sequentially

Hi everyone,

I’m working on a UXP plugin for Photoshop that exports a large number (up to 10,000) image files from a single document. This works fine when saving as JPG, however, when trying to do the same with PNG files, Photoshop crashes after around 5000 images. I attached the full error report below, but I couldn’t really make much sense of it.

I’m using API version 2 with PS v23.4.2 on Windows 10. The export takes place within a modal context using executeAsModal with history suspended as I need to make changes to the document between exports. I’m fairly sure memory usage is not the issue, as the task manager shows PS only using around 4GB of the allocated ~8GB.

Here’s a list of things I’ve already tried, unfortunately the crash still occurs with all of them:

  • Using the batchPlay API instead of activeDocument.saveAs.png to save the file
  • Removing all code that changes the document between exports (effectively making my plugin only save the document 10k times)
  • Changing the PNG save options (compression, method etc.)
  • Adding a delay of about 0.5s after each save
  • Disabling Graphics Processor in the settings
  • Purging cache after each batch of 100 images

Does anyone have any ideas what the issue might be or how I may be able to work around it? I’d appreciate any suggestions, I’ve been struggling with this issue for close to a week now.

Here’s the full crash report as provided by PS as a Pastebin (can’t add it here because of the character limit): Crash Report

Did you try jumping out of modal state and back in e.g. after every 100 images?

1 Like

Thanks for the suggestion! I tried exporting the images in batches of 100, each batch within a separate executeInModal call, but unfortunately, the crash still occurs. Interestingly, all three test runs I did crashed after exactly 5164 images - not sure if theres any specific reason behind that, though.

For completeness, here’s the corresponding crash report again: Crash Report

2^12 + 2^10 + 2^5 + 2^3 + 2^2 = 5164 :smiley: Not saying it means something, just number seemed weird and it relates to binary :smiley: