Text Cache

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Mithran, Mar 28, 2012.

  1. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    14,517
    Likes Received:
    14,144
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    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.
     
    #21
  2. dax

    dax Veteran Veteran

    Messages:
    46
    Likes Received:
    4
    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: Aug 6, 2015
    #22
  3. Mithran

    Mithran Global Moderators Global Mod

    Messages:
    403
    Likes Received:
    211
    First Language:
    English
    @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.
     
    #23
  4. dax

    dax Veteran Veteran

    Messages:
    46
    Likes Received:
    4
    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.

    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?
     
    #24
  5. Mithran

    Mithran Global Moderators Global Mod

    Messages:
    403
    Likes Received:
    211
    First Language:
    English
    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.
     
    #25
  6. dax

    dax Veteran Veteran

    Messages:
    46
    Likes Received:
    4
    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.
     
    #26
  7. ZServ

    ZServ Veteran Veteran

    Messages:
    247
    Likes Received:
    64
    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:

    [​IMG]

    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:

    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!
     
    #27
  8. Mithran

    Mithran Global Moderators Global Mod

    Messages:
    403
    Likes Received:
    211
    First Language:
    English
    @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.
     
    #28
  9. ZServ

    ZServ Veteran Veteran

    Messages:
    247
    Likes Received:
    64
    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 sheep 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.
     
    #29
  10. Mithran

    Mithran Global Moderators Global Mod

    Messages:
    403
    Likes Received:
    211
    First Language:
    English
    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.
     
    #30
  11. SKGaming

    SKGaming The Hidden Member

    Messages:
    19
    Likes Received:
    4
    First Language:
    English
    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?
     
    #31

Share This Page