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

Crash when card text is too long #32

Open
Swarmotte opened this issue Nov 6, 2021 · 7 comments
Open

Crash when card text is too long #32

Swarmotte opened this issue Nov 6, 2021 · 7 comments

Comments

@Swarmotte
Copy link

HI,
Photoshop crashes for some cards like God-Eternal Kefnet or Lich's Mastery which have long rule text. I tried to find out how to correct this error but I can't.

@Investigamer
Copy link
Contributor

I was getting this same issue with rendering Toxrill but only with certain templates?

@Investigamer
Copy link
Contributor

2 more cards that crash photoshop when you try to render them:
Ao, the Dawn Sky
Reckoner Bankbuster

In keeping with the trend these both have a lot of text. I'm really not sure what could be causing it, would love to hear ideas if anyone might know?

@Investigamer
Copy link
Contributor

Investigamer commented Feb 15, 2022

I'm doing some testing with Ao, the Dawn Sky, this problem does indeed have to do with the text contents, specifically it seems for CreatureFormattedTextArea. I have yet to find a noncreature with long text that crashes the app. I took these lines:

new CreatureFormattedTextArea(
                    layer = rules_text,
                    text_contents = this.layout.oracle_text,
                    text_colour = get_text_layer_colour(rules_text),
                    flavour_text = this.layout.flavour_text,
                    is_centred = is_centred,
                    reference_layer = text_and_icons.layers.getByName(LayerNames.TEXTBOX_REFERENCE),
                    pt_reference_layer = text_and_icons.layers.getByName(LayerNames.PT_REFERENCE),
                    pt_top_reference_layer = text_and_icons.layers.getByName(LayerNames.PT_TOP_REFERENCE),
                ),

And I changed text_contents to a random small string like "eedfwefwefg" and the card renders perfectly with that text. So something about Ao, the Dawn Sky's text is causing the crash

Then I also tried manually changing the json for this creature and removed one line from the Oracle text "Look at the top seven cards of your library." and it ran fine, so the length does appear to be the issue specifically.

ALSO worth noting this very same card renders just fine in NormalClassicTemplate, but crashes for NormalTemplate. The difference between these is that the rules text is always passed through a FormattedTextArea object for the classic template, where it goes through CreatureFormattedTextArea in the NormalTemplate. I suspected the crash is being caused by the script that checks that the text isn't colliding with the power/toughness box since that's the major difference: Classic template doesn't have power/toughness inside the text box. HOWEVER, I changed the NormalTemplate to use the regular formattedtext instead of creature to test this theory... no dice, still crashes. Going to continue digging around.

Another difference between the NormalTemplate and NormalClassic is that the font size of on the PSD are different one is 8.9, one is 8.7. So I tried changing NormalTemplate to 8.7.... still crash :/

@ndepaola
Copy link
Collaborator

ndepaola commented Feb 16, 2022

turns out that photoshop crashes when you try to insert text into a textbox that's not large enough to contain it (specifically, format_text is what breaks, right at the end when all the changes are committed to the layer):

image

increasing the height of the rules text areas will solve this. in the meantime i'll have a think about how to circumvent this issue without resorting to template updates. curious that i couldn't recreate this issue with kefnet but i could with ao

edit: kefnet's rules text also exceeds the rules text layer area but doesn't crash on my machine - increasing the height of the rules text area did solve the issue for ao on my machine though - need to investigate further

image

@ndepaola
Copy link
Collaborator

greater morphling works fine so it's not a character limit

image

@Investigamer
Copy link
Contributor

Investigamer commented Feb 16, 2022

Yeah neither Kefnet nor Lich's Mastery were crashing on my end either, but that is an interesting find regarding the text box size!

EDIT: Got another card crashing - Eater of Virtue
I'll continue to edit this post with each card I find that has this issue so we can get more test cases

@Investigamer
Copy link
Contributor

Investigamer commented Jul 26, 2022

So I think I have a better way to fix this issue than the ideas I brainstormed in the past, here's what I did for proxyshop that seems to work reliably:

  • if FormattedTextArea contents 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 action descriptors being unable to assign text properties when the text is far outside the bounds or something? So, here 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 final scale_text_to_fit_reference will make the last reduction if needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants