Minimap bitmap script problem [VX Ace]

Hello everyone.

I'm using Azraven's minimap script, the problem is that sometimes in game, on the map, an error message appears all of a sudden: "Error line 361 (or 362 sometimes too) RGSSError occrured. failed to create bitmap".

To be honest, I don't really know how this error is triggered, maybe because of my game that lag due to my laptop?

Here is the script:
Spoiler: Script
Ruby:
#==============================================================================#
#                          **Azraven Minimap**                                 #
#------------------------------------------------------------------------------#
#  ** Autor: Azraven                                                           #
#  ** Versão: 1.5b                                                             #
#  ** Data: 24/12/2012                                                         #
#------------------------------------------------------------------------------#   
#  - Descrição:                                                                #
#     Este script adiciona um mini mapa circular no jogo.                      #
#  - Utilização:                                                               #
#     Cole este script na seção "Scripts Adicionais".                          #
#==============================================================================#
#  - Histórico                                                                 #
#    24/12/2012 - Início e término da versão 1.0b                              #
#    04/03/2013 - Versão 1.5b Correção de bugs e adição de novas funções.      #
#               * Correção de um bug em que não verificava corretamente o      #
#                 de determinados tiles.                                       #
#               * Correção de um bug em que tiles de grama (bush) eram         #
#                 apresentados como bloqueio.                                  #
#               * Correção de um bug em que tiles de bloqueio posicionados     #
#                 sobre tiles de grama era mrepresentados como passáveis.      #
#               * Código melhorado.                                            #
#               + Adicionado a função de mostrar os veiculos.                  #
#               + Adicionado a função de mostrar os seguidores.                #
#               + Adicionado a função para utilizar IDs de Região para         #
#                 ocultar áreas passáveis.                                     #
#    14/06/2014 * Bug relacionado ao comando "Apagar Evento Temporário"        #
#                 corrigido.                                                   #
#               * Limpeza no código.                                           #
#------------------------------------------------------------------------------#
module Azraven
  module MiniMap
    #--------------------------------------------------------------------------#
    # CONFIGURAÇÂO                                                             #
    #--------------------------------------------------------------------------#
    #Tamanho do tile do mini mapa, recomendável não usar valores menores que 3.
    TileSize = 4
    #--------------------------------------------------------------------------#
    #Ajuste do centralizamento do mini mapa, depende do tamanho do tile.
    MapOffset = -4
    #--------------------------------------------------------------------------#
    #Define a cor do jogador no mapa.
    PlayerColor = Color.new(215,215,0)
    #--------------------------------------------------------------------------#
    #Mostra os seguidores.
    ShowFollowers = true
    #--------------------------------------------------------------------------#
    #Define a cor dos seguidores no mapa.
    FollowerColor = Color.new(0,128,255)
    #--------------------------------------------------------------------------#
    #Define se irá mostrar os veiculos no map.
    ShowVehicles = true
    #--------------------------------------------------------------------------#
    #Define a cor do barco.
    BoatColor = Color.new(255,0,255)
    #--------------------------------------------------------------------------#
    #Define a cor do navio.
    ShipColor = Color.new(255,0,255)
    #--------------------------------------------------------------------------#
    #Define a cor do aeronave.
    AirshipColor = Color.new(255,0,255)
    #--------------------------------------------------------------------------#
    #Define a cor dos objetos mostrados no mapa.
    #Objetos são NPCs, portas, teleportes, baús e o que mais o usuário puder
    #imaginar.
    #Para adicionar um novo objeto use a seguinte sintaxe dentro das {}:
    #     "tag" => Color.new(R,G,B,A)
    #Onde tag é o comentário que será adiocinado a tal evento.
    #Separe cada objeto por "," sem as aspas.
    ObjectColor = {"npc" => Color.new(0,255,0),
                  "teleport" => Color.new(255,255,255),
                  "danger" => Color.new(0,0,0),
                  "mission" => Color.new(0,0,255),
                  "event" => Color.new(255,0,0),
                  "shop" => Color.new(163,76,164)}
    #--------------------------------------------------------------------------#
    #Define a cor de contorno dos objetos e do jogador.
    BorderColor = Color.new(0,0,0)
    #--------------------------------------------------------------------------#
    #Opacidade dos objetos mostrados no mapa.
    ObjectLayerOpacity = 255
    #--------------------------------------------------------------------------#
    #Posição do mapa na tela.
    #1 = Canto superior esquerdo.
    #2 = Canto superior direito.
    #3 = Canto inferior esquerdo.
    #4 = Canto superior direito.
    MiniMapCorner = 2
    #--------------------------------------------------------------------------#
    #Define se determinada região mostrará como bloqueada no mini mapa.
    #Util pra não revelar "passagens secretas".
    UseHideRegion = true
    #--------------------------------------------------------------------------#
    #Id da região caso UseHideRegion for true.
    HideRegionId = 1
    #--------------------------------------------------------------------------#
    #Cor do da área impassável do mapa.
    MapColor = Color.new(200,150,150)
    #--------------------------------------------------------------------------#
    #Cor do contorno da área impassável do mapa.
    MapBorderColor = Color.new(50,50,50)
    #--------------------------------------------------------------------------#
    #Nome do arquivo de imagem da borda do mini mapa na pasta Graphics/System.
    BorderName = "Border"
    #--------------------------------------------------------------------------#
    #Define se irá utilizar uam textura ao fundo.
    UseBGTexture = true
    #--------------------------------------------------------------------------#
    #Nome do arquivo de imagem da textura usada ao
    #fundo do mini mapa na pasta Graphics/System.
    #Obs.: A imagem deve estar com as cores invertidas.
    BackTextureName = "OldPaper"
    #--------------------------------------------------------------------------#
    #Cor de preenchimento do fundo caso nã oseja utilizado uma textura.
    BGColor = Color.new( 100, 100, 100)
    #--------------------------------------------------------------------------#
    #Opção de preencher com uma cor a área externa do mapa.
    ClearOutsideArea = true
    #--------------------------------------------------------------------------#
    #Cor utilizada para preencher a área externa do mapa.
    ClearOutsideColor = Color.new(170,90,50)
    #--------------------------------------------------------------------------#
    #Opção de dermarcar os limites do mapa.
    OutlineMapArea = true
    #--------------------------------------------------------------------------#
    #Cor da demarcação dos limites do mapa.
    OutlineMapColor = Color.new(0,0,0)
    #--------------------------------------------------------------------------#
    #Id do switch que habilita/desabilita o mini mapa.
    EnableSwitchId = 10
    #--------------------------------------------------------------------------#
    # FIM DA CONFIGURAÇÂO.                                                     #
    #--------------------------------------------------------------------------#
    MiniMapCoords = {1 => [0,0,112,112],
                     2 => [Graphics.width - 112,0,112,112],
                     3 => [0,Graphics.height - 112,112,112],
                     4 => [Graphics.width - 112,Graphics.height - 112,112,112]}
                    
  end
end
#==============================================================================#
# ** Classe Color
#==============================================================================#
class Color
  #-----------------------------------------------------------------------------
  # * Inverte o valor das cores
  #-----------------------------------------------------------------------------
  def invert
    r = 255 - self.red
    g = 255 - self.green
    b = 255 - self.blue
    a = self.alpha
    self.set(r, g, b, a)
  end
end


#==============================================================================#
# ** Classe Mini Map
#==============================================================================#
class MiniMap
 
  include Azraven::MiniMap
 
  def initialize(viewport)
    @viewport = viewport
    @playercolor = PlayerColor.dup.invert
    @followercolor = FollowerColor.dup.invert
    @boatcolor = BoatColor.dup.invert
    @shipcolor = ShipColor.dup.invert
    @airshipcolor = AirshipColor.dup.invert
    @objectcolor = ObjectColor.dup
    @objectcolor.each_pair do |key, value|
      @objectcolor[key] = value.dup.invert
    end
    @bordercolor = BorderColor.dup.invert
    @mapcolor = MapColor.dup.invert
    @mapbordercolor = MapBorderColor.dup.invert
    @clearoutsidecolor = ClearOutsideColor.dup.invert
    @outlinemapcolor = OutlineMapColor.dup.invert
    refresh
  end
 
  def refresh
    @map_id = $game_map.map_id
    @backmask = Sprite.new(@viewport)
    @backmask.bitmap = Cache::system("Back_96")
    @backmask.x = @backmask.y = 8
    @backtile = Sprite.new(@viewport)
    @backtile.blend_type = 2
    @backtile.z = 1
    @backtile.x = @backtile.y = -100
    @map = Sprite.new(@viewport)
    @map.z = 2
    @map.blend_type = 2
    @object_layer = Sprite.new(@viewport)
    @object_layer.z = 3
    @object_layer.blend_type = 2
    @object_layer.bitmap = Bitmap.new($game_map.width*TileSize + 112,
                                     $game_map.height*TileSize + 112)
    @object_layer.opacity = ObjectLayerOpacity
    @border = Sprite.new(@viewport)
    @border.bitmap = Cache::system(BorderName)
    @border.z = 4
    @border.opacity = 255
    @mask = Cache::system("Mask")
    draw_back
    draw_map
  end
 
  def visible?
    $game_switches[EnableSwitchId]
  end
 
  def draw_map
    
    front = make_map_bitmap(@mapcolor)
    border = make_map_bitmap(@mapbordercolor)
    
    result = Bitmap.new($game_map.width*TileSize + 112,
                        $game_map.height*TileSize+ 112)
                        
    result.blt(-1, 0, border, border.rect)
    result.blt(1, 0, border, border.rect)
    result.blt(0, -1, border, border.rect)
    result.blt(0, 1, border, border.rect)
    result.blt(0, 0, front, front.rect)
    
    @mapbitmap = result
  end
 
  def draw_back
    bitmap = Bitmap.new($game_map.width*TileSize+112,
                       $game_map.height*TileSize+112)
    if UseBGTexture
      bit = Cache::system(BackTextureName)
      bitmap.stretch_blt(bitmap.rect, bit, bit.rect)
    else
      bitmap.fill_rect(bitmap.rect, BGColor)
    end
    if ClearOutsideArea
      bitmap.fill_rect(0,0,bitmap.width, 56, @clearoutsidecolor)
      bitmap.fill_rect(0,0,56, bitmap.height, @clearoutsidecolor)
      bitmap.fill_rect(0,bitmap.height-56,bitmap.width, 56, @clearoutsidecolor)
      bitmap.fill_rect(bitmap.width-56,0,56, bitmap.height, @clearoutsidecolor)
    elsif OutlineMapArea
      bitmap.fill_rect(56,55,bitmap.width-112,1,@outlinemapcolor)
      bitmap.fill_rect(55,56,1,bitmap.height-112,@outlinemapcolor)
      bitmap.fill_rect(bitmap.width-56,55,1,bitmap.height-112,@outlinemapcolor)
      bitmap.fill_rect(56,bitmap.height-56,bitmap.width-112,1,@outlinemapcolor)
    end
    @backtilebitmap = bitmap
  end
 
  def draw_object_layer
    for event in $game_map.events.values
      unless event.list.nil?
        for item in event.list
          if item.code == 108 or item.code == 408
            if @objectcolor.has_key?(item.parameters[0])
              draw_object(event.real_x*TileSize+56,
              event.real_y*TileSize+56,
              @objectcolor[item.parameters[0]])
            end
          end
        end
      end
    end
    if ShowFollowers
      unless $game_player.vehicle
        $game_player.followers.each do |follower|
          draw_object(follower.real_x*TileSize+56,
                      follower.real_y*TileSize+56,
                      @followercolor) if follower.visible?
        end
      end
    end
    if ShowVehicles
      unless $game_map.airship.transparent
        draw_object($game_map.airship.real_x*TileSize+56,
                $game_map.airship.real_y*TileSize+56,
                @airshipcolor)
      end
      unless $game_map.ship.transparent
        draw_object($game_map.ship.real_x*TileSize+56,
                $game_map.ship.real_y*TileSize+56,
                @shipcolor)
      end
      unless $game_map.boat.transparent
        draw_object($game_map.boat.real_x*TileSize+56,
                $game_map.boat.real_y*TileSize+56,
                @boatcolor)
      end       
    end
    draw_object($game_player.real_x*TileSize+56,
                $game_player.real_y*TileSize+56,
                @playercolor)
  end
 
  def draw_object(x, y, color)
    @object_layer.bitmap.fill_rect(x, y, TileSize, TileSize, @bordercolor)
    @object_layer.bitmap.fill_rect(x+1, y+1, TileSize-2, TileSize-2, color)
    @object_layer.bitmap.clear_rect(x,y,1,1)
    @object_layer.bitmap.clear_rect(x,y+TileSize-1,1,1)
    @object_layer.bitmap.clear_rect(x+TileSize-1,y,1,1)
    @object_layer.bitmap.clear_rect(x+TileSize-1,y+TileSize-1,1,1)
  end
          
  def make_map_bitmap(color)
    bitmap = Bitmap.new($game_map.width*TileSize + 112,
                       $game_map.height*TileSize + 112)
    for x in 0..$game_map.width - 1
      for y in 0..$game_map.height - 1
        if $game_map.airship_land_ok?(x, y) || $game_map.bush?(x, y)
          if UseHideRegion
            bitmap.fill_rect(x*TileSize+56,
                             y*TileSize+56,
                             TileSize, TileSize,
                             color) if $game_map.region_id(x, y) == HideRegionId
          else
             next                 
          end
          if $game_map.bush?(x, y)
            unless $game_map.passable?(x, y, 4)
               bitmap.fill_rect(x*TileSize+56, y*TileSize+56, TileSize, TileSize, color)
            end
          end
          next
        end
        bitmap.fill_rect(x*TileSize+56, y*TileSize+56, TileSize, TileSize, color)
      end
    end
    bitmap
  end
 
  def update_object_layer
   @object_layer.bitmap.clear
   draw_object_layer
  end
 
  def dispose
    @backmask.dispose
    @backtile.dispose
    @map.dispose
    @object_layer.dispose
    @border.dispose
  end
 
  def update
    if @map_id != $game_map.map_id
      dispose
      @map_id = $game_map.map_id
      refresh
    end
    @backmask.visible = visible?
    @backtile.visible = visible?
    @map.visible = visible?
    @object_layer.visible = visible?
    @border.visible = visible?
    if visible?
      @map.bitmap = @mapbitmap.dup
      @backtile.bitmap = @backtilebitmap.dup
      sx = $game_player.real_x * (TileSize * -1) + MapOffset
      sy = $game_player.real_y * (TileSize * -1) + MapOffset
      update_object_layer
      @map.x = @backtile.x = @object_layer.x = sx
      @map.y = @backtile.y = @object_layer.y = sy
      @backtile.bitmap.blt(sx*-1, sy*-1,@mask,@mask.rect)
      @map.bitmap.blt(sx*-1, sy*-1,@mask,@mask.rect)
      @object_layer.bitmap.blt(sx*-1, sy*-1,@mask,@mask.rect)
    end
  end
end
#==============================================================================#
# ** Classe Spriteset_Map
#==============================================================================#
class Spriteset_Map
 
  alias azraven_mini_map_init initialize
  alias azraven_mini_map_updt update
  alias azraven_mini_map_disp dispose
 
  include Azraven::MiniMap
 
  def initialize
    create_minimap
    azraven_mini_map_init
  end
 
  def create_minimap
    viewport = Viewport.new(Graphics.width - 112,0,112,112)
    viewport.rect.set(MiniMapCoords[MiniMapCorner][0],
                      MiniMapCoords[MiniMapCorner][1],
                      MiniMapCoords[MiniMapCorner][2],
                      MiniMapCoords[MiniMapCorner][3])
    viewport.z = 50
    @minimapa = MiniMap.new(viewport)
  end
 
  def dispose
    azraven_mini_map_disp
    @minimapa.dispose
  end
 
  def update
    azraven_mini_map_updt
    @minimapa.update
  end
end
#==============================================================================#
# ** Fim do Script
#==============================================================================#

Thanks for any answers.
What are you doing before the error shows up? Maybe it has nothing to do with this script.
Do you have a backtracer script in your project?
I was just moving my character around the map.

The error in question was "Script 'Minimap - Azraven' line 361: RGSSError occured.
failed to create bitmap"

Here's the backtrace:
Spoiler: Backtrace
RGSSError: failed to create bitmap.
Backtrace:
Minimap - Azraven:361:in `initialize_copy'
Minimap - Azraven:361:in `initialize_dup'
Minimap - Azraven:361:in `dup'
Minimap - Azraven:361:in `update'
Minimap - Azraven:407:in `update'
Victor Engine - Fog:475:in `update'
TheoAllen - Map Projectiles:206:in `update'
MOG_Weather_EX:768:in `update'
Text on screen (TheoAllen):288:in `update'
Effet 2:257:in `update'
Scene_Map:65:in `update'
TDS - Scene Skip:244:in `update'
Popup (Holy87):170:in `update'
Scene_Base:14:in `main'
MOG_Weather_EX:852:in `main'
SceneManager:23:in `run'
Global System Options (Sixth):450:in `run'
Main:7:in `block in <main>'
:1:in `block in rgss_main'
:1:in `loop'
:1:in `rgss_main'
Backtrace:243:in `block in rgss_main'
Backtrace:99:in `with_exception_handling'
Backtrace:242:in `rgss_main'
Main:7:in `<main>'
ruby:in `eval'
Most likely a script conflict. How many other scripts do you have?
Are you playing from a saved game or new?
Have you moved the script up and down your script list?
I tested your script and it worked fine.
I was able to test and I think I understood how the error is triggered.

It's not because of a script conflict because I tested in a new project with only this one.

When the map is too big (mine is 93x93) and when I move my character in it, after a while the message mentioned above appears.
Again, Strange. Taking what you said I tested on a 400x200 map. No problems other than a studder every two seconds (probably from the map being so big). Changed to the size you stated and no issues. Blank project as well. How long of a while is "a while"?
Yes it's really very strange, here is the demo which normally contains the error.
It happens between 30s-1min I would say.

Well I have a possible solution. It is partly your fault and partly the programs fault.

First a question. Why do you have every database at max quantity?
Actors -> 5000
Classes -> 5000
Skills -> 5000
Items -> 5000
Weapons -> 5000
Armor -> 5000
Enemies -> 5000
Troops -> 5000
States -> 5000
Common events -> 5000

I lowered all of them to just above the number you have in the database and I did not get the error.
Yes you are right, it's my fault 😅, I had used a database limit breaker script a long time ago, I didn't think it could be the cause.

Anyway, thanks for helping me to find a solution, for now it seems to work fine but I'll keep testing a bit to see if the error reappears anyway.

Original thread: https://forums.rpgmakerweb.com/threads/minimap-bitmap-script-problem-vx-ace.144372/