Investigamer/Proxyshop

Long Text Entry Crash

Closed this issue · 5 comments

This bug has been a long existing Photoshop issue, I'm going to track our test cases here and continue developing an elegant long term solution.

Describe the bug
Photoshop crashes when text is inserted that overly exceeds the bounds of a TextLayer paragraph box.

To Reproduce
Try to render Animate Dead for example (as of Proxyshop v1.1.2)

Your system:
This bug occurs regardless of Python or Windows version, and has been demonstrated on all Photoshop versions compatible with Proxyshop.

The Solution:
Previously a solution was added that decreases the font size by .75 if the oracle text being entered is over 300 characters. We now know that for even longer texts such as Animate Dead (420 characters) this number is not enough. As of the developmental Proxyshop (planned 1.1.3 release) I have adjusted this behavior to scale down by 1 pt (EDIT: Increased from .75 to fix Reckoner Bankbuster) for every 100 characters above 200 the text is. This fixes Animated Dead, but we need to continue to catalog known failed cards from the past and ensure this issue is fixed in all cases. I will catalog known bugged cards below and whether this solution solves the issue.

Bugged Cards Status
Reckoner Bankbuster Fixed
Animate Dead Fixed
Ao, the Dawn Sky Fixed
Eater of Virtue Fixed
God-Eternal Kefnet Fixed
Lich's Mastery Fixed
Toxrill, Corrosive Snail Fixed
Bronze Tablet Likely Fixed
Giant Oyster Likely Fixed
Cooperation Likely Fixed

I ran into this issue with Firkraag, Cunning Instigator as well. Currently unable to test your most recent fix since I'm running into a ModuleNotFoundError: No module named 'get_image_size'

Ok, so after resolving my dependency issue by running pip install -r requirements.txt I was able to get Firkraag, Cunning Instigator to render (using Extended template)! However, I immediately ran into the hanging issue again during the text box resizing when trying to render Nalia de'Arnise (using Expedition template) during the "Formatting text..." stage.

Error was as follows:

File "D:\Users\davidianstyle\Code\MTG-Proxyshop\proxyshop\templates.py", line 241, in execute
     this_layer.execute()
   File "D:\Users\davidianstyle\Code\MTG-Proxyshop\proxyshop\text_layers.py", line 372, in execute
     super().execute()
   File "D:\Users\davidianstyle\Code\MTG-Proxyshop\proxyshop\text_layers.py", line 287, in execute
     ft.format_text(self.contents + "\r" + self.flavor_text, self.italic_text, self.flavor_index, self.centered)
   File "D:\Users\davidianstyle\Code\MTG-Proxyshop\proxyshop\format_text.py", line 495, in format_text
     app.executeAction(idsetd, desc119, NO_DIALOG)
   File "D:\Users\davidianstyle\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\photoshop\api\application.py", line 
355, in executeAction
     return self.app.executeAction(event_id, descriptor, display_dialogs)
   File "D:\Users\davidianstyle\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\comtypes\client\lazybind.py", line 182, in caller
     return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
   File "D:\Users\davidianstyle\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\comtypes\automation.py", line 745, in _invoke
     self.__com_Invoke(memid, riid_null, lcid, invkind,```

I keep forgetting to make commits but I finally designed a robust fix for the long text entry crash a couple days back, just pushed changes so pick them up and let me know if that does it for ya! I tested Nalia de'Arnise on Expedition template and working on my end.

Here's an outline of how the fix works:

  • if card has over 280 characters, insert the contents and the flavor text, then:
  • scale_text_to_fit_height() -- New function similar to scale to fit reference, feed it the height of the reference increased by 1%
  • everything else in the text_layers class runs as normal afterwards (insert text, format it, scale it, add divider, etc)

I realized the crash happens during format_text(), not when the text is initially inserted. It must have something to do with working with the text using action descriptors when the text doesn't fit the textbox. So, we do a pre-format resize of the text till its low enough to almost fit.

The reason I chose to use the height of the reference + 1% is because this scaling is being done before the text is formatted. The reason we scale after formatting is to account for any size loss caused by formatting the symbols and such. I wanted to leave just enough headroom to keep outside the bounds and the traditional scale_text_to_fit_reference() will make the last reduction if needed.

Awesome, that worked! Results uploaded to my drive.

This appears to be fixed, so I'm going to close this. Will reopen if another card ends up crashing in the future!