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

Long Text Entry Crash #9

Closed
Investigamer opened this issue May 25, 2022 · 5 comments
Closed

Long Text Entry Crash #9

Investigamer opened this issue May 25, 2022 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@Investigamer
Copy link
Owner

Investigamer commented May 25, 2022

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
@davidianstyle
Copy link
Contributor

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'

@davidianstyle
Copy link
Contributor

davidianstyle commented Jul 28, 2022

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,```

Investigamer added a commit that referenced this issue Jul 28, 2022
- Fixed long text entry crash, see Issue #9. Deprecated fix_length arg
- Silvan Extended Template: Added more support for colorless cards
- New helper function `check_fonts()`, pass a list of fonts to check if they exist in Photoshop
- Added optional args for layer and reference to align, align_vertical, align_horizontal
- Deprecated ability words list, implemented new regex to detect these scenarios automatically
- Moved re.compile for card_info function to top of core for minor execution time improvement on large operations
@Investigamer
Copy link
Owner Author

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.

@davidianstyle
Copy link
Contributor

Awesome, that worked! Results uploaded to my drive.

@Investigamer Investigamer added the bug Something isn't working label Nov 5, 2022
@Investigamer
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants