Text Cache

Archeia

Level 99 Demi-fiend
Developer
Joined
Mar 1, 2012
Messages
15,056
Reaction score
15,336
First Language
Filipino
Primarily Uses
RMMZ
It's Window_Help yeah. I guess it is one of those things that are just super finicky to do. Is ok! I notice it happens to almost all pixel/bitmap fonts so it got me thinking what's up with it.
 

dax

Veteran
Veteran
Joined
Jul 17, 2015
Messages
46
Reaction score
4
Primarily Uses
Not sure if I should've opened a new thread or here it's fine.

Anyway, I'm having problems with this script that might force me to remove it before my submission unless I understand what's the problem in such short time. :(

Basically... the game randomly crashes. It happened once today, once yesterday. Every time, I restarted it without doing anything, and it didn't crash anymore for a lot of time. Therefore, I can't understand what's the deal.

This is the error log:

Text Cache:161:in `draw_text_cached': undefined method `-' for nil:NilClass, NoMethodError
    from Text Cache:132:in `draw_text'
    from Window_Base:196:in `draw_text'
    from Window_Base:276:in `process_normal_character'
    from Window_Base:268:in `process_character'
    from Word:87:in `process_character'
    from Window_Base:211:in `draw_text_ex'
    from Window_Help:41:in `refresh'
    from Window_Help:20:in `set_text'
    from Scene_File:39:in `create_help_window'
    from CustomScene:253:in `start'
    from Scene_Base:12:in `main'
    from SceneManager:22:in `run'
    from Main:10:in `block in <main>'

Lines 161 and 162 are these ones:

    y += (height - text_height) / 2 # horizontal center
    buf = -TEXT_SIDE_BUFFER

if anyone has any suggestions, I'd appreciate. Should I put this script above or under everything else ?

edit: all right, I just got a suspicion: in the past I've had crashes when I was loading saved games which actually had differences (in particular, different file pictures name would make the game crash related to the cache). I wonder if it might be something similar. In that case, I wouldn't have to worry, hopefully...
 
Last edited by a moderator:

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
216
First Language
English
Primarily Uses
@dax - Your version has a different line number than the most recent one I am looking at. Are you using an older version?


Whats happening here is that a nil height argument is getting passed. This line is the first one in the draw text that checks height argument. You might get a different error message without Text Cache installed or have it point to a different area, but height should only be nil at this point if it is passed as a nil to draw_text, or there were too few arguments passed to draw_text where it wouldnt work anyway. My script should correctly get the height argument if a rect was passed, or if the height argument was passed in the correct order. Since it looks like you are going through another custom script to pass argument into process_character which passes arguments into process_normal_character, it is possible something went wrong when the height argument was assigned through this script. If, for example, calc_line_height were redefined and possible to return a nil value, but only in certain situations, the error would crop up "randomly". I'm not sure what the "Word" script on the trace callback of the list you provided is, but since it is messing with process_character, that might be a good place to start. The error you posted is also related to a help window, so that could help reproducing it. Once you can reproduce it, it is a lot easier finding a solution.


You could print the arguments passed into draw_text into the console, but that only helps if you can actually reproduce the crash. Just add the line "p args" under "def draw_text(*args)" (no quotes on either) and keep an eye on the console if you get another crash, then you can see for sure what the arguments passed were.


This shouldn't have anything to do with saved games, since Text Cache doesn't touch saves and the cache is kept during runtime only.
 

dax

Veteran
Veteran
Joined
Jul 17, 2015
Messages
46
Reaction score
4
Primarily Uses
Thanks a lot for the long and well-thought long response!

It is

# Text Cache v 1.03

however I just tried pasting it again from this OP post and you're right, the line number now appears different.

Weird. I'm not sure what was different, I never touched it.

The "Word" script is

 ** Word Wrapping Message Boxes, by: KilloZapit

Actually... I'm not even sure if it's really useful. It kinda went into my project but I never used its tags >_>'. Maybe I can take it out.

You could print the arguments passed into draw_text into the console, but that only helps if you can actually reproduce the crash. Just add the line "p args" under "def draw_text(*args)" (no quotes on either) and keep an eye on the console if you get another crash, then you can see for sure what the arguments passed were.

This shouldn't have anything to do with saved games, since Text Cache doesn't touch saves and the cache is kept during runtime only.

@dax - Your version has a different line number than the most recent one I am looking at. Are you using an older version?
Thanks, I just added it.

 alias draw_text_vxa draw_text
  def draw_text(*args)
    p args
    return draw_text_vxa(*args) if NO_FIX

Like this, right?
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
216
First Language
English
Primarily Uses
Yes, like that. Make sure you take it out before you release the game. The line is just there so the console will display the arguments passed in, so if you happen to get another crash you can check the console and see exactly what the last arguments passed were.
 

dax

Veteran
Veteran
Joined
Jul 17, 2015
Messages
46
Reaction score
4
Primarily Uses
I did not make it in time for the contest anyway despite an all nighter, unfortunately. But I'm very thankful for your help. Hilariously, I never had more crashes, but I'll still keep it.
 

ZServ

Veteran
Veteran
Joined
Jun 16, 2014
Messages
259
Reaction score
71
Primarily Uses
I was having issues with Sleek Gauges, found here:
http://forums.rpgmakerweb.com/index.php?/topic/25747-sleek-gauges/

The issue can be seen in the above thread, or here:



The text would draw itself strangely, as seen on the last 2 and the 9 on the left. These images were taken seconds apart. Now, I have NO idea if this is an issue with Sleek Gauges or the Text Cache script, but TamFey of reddit was incredibly helpful in taking a peek at the situation, and presented the following:

Go to the last line of the aliased draw_text method (line 130 for me).

The line should be

draw_text_cached(x, y, width, height, text, align) Now above that you write

x -= alignThat's it. That line offsets the extra width that the script adds to text lines.

Mithran used the same line for squeezed text lines, but forgot to add it when the lines are not squeezed.
I couldn't tell you if this was an intentional decision or your part or not, Mithran, but I figured I'd present this information here and in the Gauges thread, in case anyone needed it or it was an issue on your end. Sorry to be a bother!
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
216
First Language
English
Primarily Uses
@ZServ -


Actually, thats not the purpose of that line. Its not exactly intuitive written like that, even with the comments, so I'll explain here


VX Ace draw text command has the unfortunate design flaw of invoking the squeeze algorithm if the text will fit exactly in the space drawn. In other words, if you use the method Bitmap#text_size to see how much room you need to draw text, then attempt to draw text to that rect, it will squeeze it and act like there is no room. This branch of this method is only used if squeeze is allowed and bypasses the cache completely. In other words, the text drawn with this method is not necessarily squeezed, but it can be squeezed, because it uses the default text draw method. The arguments passed into the method are passed on to this method with two small modifications. First, I add two pixels to the available width to draw in. This is so text passed to the original draw text method is not squeezed until it is actually necessary. Why two pixels and not one? Well, so I can have the line in question, x -= align. If it is left aligned, align is 0 and the origin of the text does not change. If it is center, align is 1 and we shift the whole draw request one pixel to the left so the center point remains exactly the same as if I never added the two pixels. Same with right justified, align is 2, we shift two pixels left, and the right edge of where the text is supposed to be is preserved.


Cached text, on the other hand, is a collection of single letters copied into separate bitmaps and then copied in one by one. By design, it draws left to right and it has to ignore text squeezing. However, it calculates where the text should be given your alignment and space, and places it there for you. To my knowledge and through every test I have run, this seems to be working correctly.


Now, onto your issue. What are your results without text cache installed? I'm seeing that the text goes beyond the bar, but I think you are talking about the text having slightly darker outlines in the left picture. What it looks like it happening here is that the same text is being drawn over itself more than once, meaning the area cleared out is smaller than the area the text is drawn to.


So, it could be one of a few things.


1) My script is going out of the requested area when drawing text. While certainly possible, this shouldn't happen, especially for right justified draws. If the text is too big to fit in the area, caching is disabled and squeezing is enabled. Left hand justified text WILL do this if given an invalid text width to draw to, to prevent another crash where you are unable to draw a single string longer than approximately the width of the screen. Since the text pictured above looks neither left justified or over the width of the screen, I doubt this is the issue.


2) The script is drawing to a bigger area than it is clearing. I'm not sure how drawing the same text over itself works for the semi-transparent pixels, but Bitmap#blt will blend the value. The fact that the text goes slightly to the right of the bar may be related to this, if only the area where the bar is drawn is cleared.


3) The font you are using is reporting its actual size to RGSS3 incorrectly via Bitmap#text_size. Possible, but I've never come across this before.


I will let you know when I've investigated more, but on a cursory reexamination of my script, the math seems to check out.
 

ZServ

Veteran
Veteran
Joined
Jun 16, 2014
Messages
259
Reaction score
71
Primarily Uses
Doesn't happen without text cache installed.

Don't think it's 1, it could very well be 2 (it's what I anticipate), 3 sounds.. unlikely. From what I know of the Sleek Gauges script, the rendering "frame" (I don't know the technical term, viewport? window? iono, area that **** is rendered in), is a set size, and then it draws everything on that viewport, just in a particular order, text being last. So, considering it ONLY happens when the gauges would re-draw themselves, I would imagine it's 2. But, wasn't sure, so I figured I'd give you a heads up for what fixed it for me.
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
216
First Language
English
Primarily Uses
Its the gauges script. When it draws numbers to an area of less than 96 pixels, it overdraws the right edge by two pixels. The area it clears out before subsequent draws is two pixels smaller than the area it draws to. It is in the draw_text method, at the very bottom of the script:

Code:
  def draw_text(x,y,w)    return unless @cur_val    @window.change_color(@window.system_color)    @window.draw_text(x, y, 30, @window.line_height, @vocab)    @window.change_color(@window.normal_color)    @window.change_color(@window.crisis_color) if @cur_val < @max_val / 4    xr = x + w    if w < 96      @window.draw_text(xr - 40, y, 42, @window.line_height, @cur_val.to_i, 2)    else      @window.draw_text(xr - 92, y, 42, @window.line_height, @cur_val.to_i, 2)      @window.change_color(@window.normal_color)      @window.draw_text(xr - 52, y, 12, @window.line_height, "/", 2)      @window.draw_text(xr - 42, y, 42, @window.line_height, @max_val, 2)    end  end
specifically, the line reading
Code:
      @window.draw_text(xr - 40, y, 42, @window.line_height, @cur_val.to_i, 2)
Where it draws text starting 40 pixels left of the right edge of the bar, with a width of 42 pixels and right justified, so the right edge of the draw is always two pixels beyond the bar. Change that first 40 to 42 will bring everything in line. The reason the interaction probably wasn't caught sooner is because not every font actually has solid pixels on the right most edge of its draw, and normal text draws likely overwrite the semi-transparent pixels rather than blend them like blt. With the original suggested fix by TamFey, this specific issue would have also gone away, because that also would shift the draw two pixels to the left, but it would mean every other right justified text draw would also be two pixels further to the left as well.
 

SKGaming

The Hidden
Member
Joined
Dec 16, 2015
Messages
19
Reaction score
4
First Language
English
Primarily Uses
When I used this script it got rid of my initial problem, but I've found a new one.

It keeps giving me this error message when I try to test my game:

"Script 'Cache' line 21: NameError occured

uninitialized constant Object::Scene_Base"

What do I do?
 

PnFGaming

Warper
Member
Joined
Jul 17, 2019
Messages
2
Reaction score
0
First Language
English
Primarily Uses
RMVXA
Hey...I don't know if you're still active in this..but I'm having a problem. Ya see, I've been testing this a lot, but it seem to crash on Skills, Items, Status Menus whenever I have Consolas as the font. Error on Line 212. I don't why this is the case, and I dont know if it's any other script thats causing this.
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
245
Reaction score
90
First Language
English
Primarily Uses
RMXP
So that line in question is
Code:
return @cache[key] = empty_bitmap if (rect.height == 0 || rect.width == 0)
Looking at the method as a whole, key is not even defined...must have been a sloppy copy-paste oversight. The only way it could reach this point is if the character the script was trying to generate & cache returned a 0x0 rectangle (i.e. Consolas does not have a glyph for that character).

You can put right above that line
Code:
puts char.inspect
and see in the debug console what character is giving you troubles, and then check that your Consolas font actually supports that character.

Meanwhile, you can probably fix this bug by replacing the line with
Code:
return @cache[fontary + [char]] = empty_bitmap if (rect.height == 0 || rect.width == 0)
This is purely speculation and untested.
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
216
First Language
English
Primarily Uses
Fixed the empty character issue. 'key' is now assigned earlier in the method.
 

Wyrelade

Wyrelade - The one and only.
Veteran
Joined
Apr 11, 2014
Messages
62
Reaction score
22
First Language
Finland
Primarily Uses
RMVXA
Amazing! life saver my dude! Very lightweight optimization plugin for a quite resource heavy game I got going on.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

X[ oh gawd.... I dropped my super expensive laptop on my hard tile floor! It still comes on and all, but now Im worried its gunna start screwing up in the near future.... I hope not, cant afford to replace stuff like that. :(
I wrote a nice animated preloading system for mv+mz today. It only supports graphic assets atm, should it support audio too? See it in action in my recent minigame @
I posted my first commercial game on the forums, and now waiting for approval.
fingers crossed.
TMW the air quality is so bad, your hair changes color every time you wash it. :LZYyuck:
Finished two animations today. :kaojoy:

Forum statistics

Threads
103,002
Messages
996,648
Members
134,485
Latest member
olivecat
Top