RPG Maker Forums

Okay, I've been going over the code on my own for quite some time already and found no clues, so I decided that now would be a good time to ask for help... :|

I'm investigating a bug reported for my plugin, TAA_BookMenu, which appears only when using Yanfly's Message Core WordWrap feature:
1579805368729.png
You can reproduce the issue with the Demo project, just include Yanfly's plugin, pick a long book text (like the one in the example above), remove all manual line breaks and activate Yanfly's wordwrap function (either forcing it for all texts in the plugin parameters or by adding the tag <WordWrap> at the beginning of the book text).

I've been turning the code upside down (both mine and Yanfly's), but haven't been able to find any threads to start unraveling this thing.

I would appreciate if anyone could help me out here!

EDIT: Ok, it took me a while but I figured out what was going on (issue is fixed on TAA_BookMenu v1.4.0 or above). If anyone else stumble into this post trying to fix a similar issue, here's a short technical explanation in the spoiler tag below.

After a bit of debugging, I started thinking the issue would be a bug in PIXI. That worried me, because if I were right fixing it would be quite complicated. But after digging deeper I found out that it was related to PIXI, but was being caused by my own code, and then I started to see the solution.

So, to draw the text in a window we first have to create the contents object, and for that we have to determine its dimensions (width and height). Without wordwrap that's an easy task. Width is the same as the window (minus padding) and height can be calculated with an Window_Base function called calcTextHeight. But when using wordwrap, the real text height is determined at the text drawing phase, as each character is draw individually to check whether the whole word will fit in the available width or not.

Artificially incrementing the height variable works (like multiplying it by a high number, like 10 or 100), but you risk creating a contents object so big that it exceeds the WebGL maximum allowed memory (which value depends on your GPU). The result is a black square where the text should be when you try to load the text.

I couldn't find a way to automatically fix that for both wordwrap and non-wordwrap users alike, so I included a parameter to enable or disable the fix, which consists on trying to "guess" the text height beforehand. To do that, the code counts the number of characters on the text and divide by the window width, resulting in a rough estimate to how many lines it may require. However, the dev can still force linebreaks, so I also count how many of them I can find in the text and add that to the number of lines. The resulting number is multiplied by the line height. And there you go, a rough estimate as how big your text will get.

At the end, I compare the result from calcTextHeight to this number, and choose the higher one as the contents height.

If you create a huge wall of text you can still stumble into the black square issue, but I have run tests with up to 102 lines, still good. Considering the plugin's expected use, that is already a crazy high number. If you need to go bigger than that I strongly advise you to break your text into smaller bits! :p

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top