The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: Nessiah on March 08, 2012, 09:29:38 PM

Title: [VXA]Picture Bug Fix
Post by: Nessiah on March 08, 2012, 09:29:38 PM
Picture Bug Fix
Authors: Raizen884, Johnbolton, Gab!
Version: 1.0
Type: Bug Fix

Introduction

While I was beta testing for VXAce, I noticed that after a specific amount of picture disposal the game will start lagging. This is more obvious when you disposed 4 1280x1280 pictures and a few smaller amounts. The sad thing is that the lag is permanent. Trying Cache.clear with GC.start didn't help me with this problem. Luckily, a few guys from CentroRPGmaker found out about this and has created a fix. They also shared it with the English community and I figured I'll post it in here as well.

Note: This has already been reported to Eb! And we're not sure yet if this fix will be applied, but just in case :)



Features


Screenshots

N/A

Demo

No demo.

Script

Spoiler for:
Code: [Select]
#==============================================================================
#                           Picture Bug Fix
#------------------------------------------------------------------------------
# Author : Raizen884
# Credits : JohnBolton, Gab!
# Community : www.centrorpgmaker.com
# This script corrects a bug in the default scripts in which pictures continued
# to be updated even after they were erased, which caused lag.
#------------------------------------------------------------------------------
# Place this script above all other scripts in the Materials section.
#==============================================================================
class Sprite_Picture < Sprite
    def update
        super
        if @picture.name != ""
            update_bitmap
            update_origin
            update_position
            update_zoom
            update_other
        else
            self.bitmap.dispose if self.bitmap != nil
        end
    end
end


    Instructions

    In the script.

    Compatibility

    Should work with anything.

    Credits and Thanks




    Author's Notes
    There were 2 members which were trying to fix this, me and JohnBolton, it took some time because there was no error log, but JohnBolton, which has some scripts here found where was the problem. Also special thanks for Gab! which helped us out also, even though it is a very small script, it took some time to find where was the problem.
    Enjoy! :)
    Title: Re: [VXA]Picture Bug Fix
    Post by: Nessiah on March 12, 2012, 03:25:43 PM
    Picture Bug Fix
    Author: Mithran
    Version: 1.0
    Type: Bug Fix

    Introduction

    The problem is caused when a picture is erased it holds an assoicated "picture" object in memory as long as you stay on the same scene. Every time that picture object comes up, it creates a NEW blank bitmap, every frame, basically if you want it to lag, create a lot of blank pictures when they get garbage collected, it lags. Each erased picture creates a single 32x32 blank bitmap to associate itself with, every frame, same with any picture shown as (none). Since the lag is caused by garbage collection, which is basically uncontrollabe with Ruby.

    The reason why it constantly creates new blank pictures is because the base scripts check for the picture name. And if it's "" (aka no picture name), it keeps creating. When a picture is erased, it sets to ""


    Features


    Screenshots

    N/A

    Demo

    No demo.

    Script

    Spoiler for:
    Code: [Select]
    #==============================================================================
    # ? Mithran Picture Bug Fix
    # -- Created: 3/12/2012
    #==============================================================================
    # The problem is caused when a picture is erased it holds an assoicated "picture"
    # object in memory as long as you stay on the same scene. Every time that picture
    # object comes up, it creates a NEW blank bitmap, every frame, basically if you
    # want it to lag, create a lot of blank pictures when they get garbage collected,
    # it lags.

    # Each erased picture creates a single 32x32 blank bitmap to associate
    # itself with, every frame, same with any picture shown as (none). Since the lag
    # is caused by garbage collection, which is basically uncontrollabe with Ruby.
    #
    # The reason why it constantly creates new blank pictures is because the base
    # scripts check for the picture name. And if it's "" (aka no picture name),
    # it keeps creating. When a picture is erased, it sets to ""
    #
    # This script fixes that.
    #==============================================================================

    class Sprite_Picture
      def update_bitmap
        if @picture.name != @pic_name
          self.bitmap = Cache.picture(@picture.name)
        end
        @pic_name = @picture.name
      end
     
    end


    class Spriteset_Map
     
      def update_pictures
        $game_map.screen.pictures.each do |pic|
          @picture_sprites[pic.number] ||= Sprite_Picture.new(@viewport2, pic)
          @picture_sprites[pic.number].update
          if pic.name == ""
            $game_map.screen.pictures.remove(pic.number)
            @picture_sprites[pic.number].dispose
            @picture_sprites[pic.number] = nil
          end
        end
      end

    end

    class Game_Pictures
     
      def remove(index)
        @data[index] = nil
      end
     
    end

      Instructions

      In the script.

      Compatibility

      Should work with anything.

      Credits and Thanks



      Author's Notes
      The difference with this one and the previous one is that it doesn't remove the stored picture data. It's still a stored empty image.

      [/list]
      Title: Re: [VXA]Picture Bug Fix
      Post by: Helladen on July 27, 2012, 12:09:12 AM
      I'm kind of confused, do I get both or just the second one? I read the descriptions of both and still not sure if I need them both.
      Title: Re: [VXA]Picture Bug Fix
      Post by: Nessiah on July 29, 2012, 12:32:52 AM
      Just get the 2nd one if you're using the Japanese version :3
      Title: Re: [VXA]Picture Bug Fix
      Post by: Helladen on July 29, 2012, 04:11:42 PM
      I am using English version.