[Resolved] Bitmap Dispose problem.

Started by chaucer, February 20, 2015, 05:05:04 pm

Previous topic - Next topic

chaucer

February 20, 2015, 05:05:04 pm Last Edit: February 20, 2015, 06:55:58 pm by chaucer
So I noticed this a few times I'm not sure whether I'm missing something or if I'm doing this wrong completely, But every time i draw a bitmap I have this weird issue where when I dispose it, it disposes slowly. I.E. I call dispose method and it takes anywhere from 0-3 seconds to dispose, it's sort of random. Here's an example from what I'm trying to write now.

def update_graphic
   
   if @timer_1 == 24
     @charge_hud = Sprite.new
     @charge_hud.bitmap = Bitmap.new(64,24)
     @charge_hud.bitmap.fill_rect(0,0,64,24,Color.new(0,0,0,255))
   end

 end

 def dispose
   if @charge_hud != nil
     @charge_hud.dispose
     @charge_hud.bitmap.dispose
   end
 end
end


It all looks logical to my eyes, but when I call it it doesn't seem to respond to dispose right away. I think it might be part of the issue that I'm calling it from Scene Map?

class Scene_Map
 alias main_charge main; alias update_charge_later update
def main
   @charging = Charge_Skills.new
   main_charge
   @charging.dispose
 end
 
 def update
   update_charge_later
   @charging.update
 end
end


Can anyone please tell me where I messed up? I've been messing with this for quite some time, I thought I'd post here before it completely frustrates me haha.(Also sorry if this issue had been discussed before, I did search, but honestly it wasn't that thorough.)

KK20

Have you tried calling Bitmap#dispose before Sprite#dispose

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

chaucer

I have, it's still the same issue =/ I tried the way you mentioned, i tried using them both alone, i tried just putting bitmap and sprite both = nil, I can't seem to make it work.

KK20

You made sure you don't have any other scripts placed below that modify Scene_Map#main? Basically could just put a print statement just above the call to dispose.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

chaucer

February 20, 2015, 06:25:37 pm #4 Last Edit: February 20, 2015, 06:33:27 pm by chaucer
well, it will show a printed message, but it won't dispose still untill after a short delay, and there's nothing else below. I'm not sure whats up with it.

EDIT: here's the full script maybe i missed something.. or idk.

Spoiler: ShowHide

module Skill_Charges
 #Use a charging sprite?
 Charge_Sprite = false
 #the sound effect to be played when skill is ready.
 Sound_Effect = '155-Support13'
 #if sound effect should repeat
 Repeat_Sound = false
 #Setup for weapons.
 def self.weapon_charge(weapon_id)
   case weapon_id
  #when weapon_id then return skill id
   when 1 then return 1
   when 2 then return 2
   when 3 then return 3
   when 4 then return 4
   when 5 then return 5
   when 6 then return 6
   end
   return 0
 end

end

class Charge_Skills
 
 def initialize
   @weapon_id = $game_party.actors[0].weapon_id
   @original = $game_player.character_name_org
   @timer_1 = 0
   @timer_2 = 0
   @play_se = false
   @battlers = $game_system.battlers_number
   @move_x = $game_player.real_x -  $game_map.display_x
   @move_y = $game_player.real_y -  $game_map.display_y
 end

 def update
   
   if $game_party.actors[0].weapon_id != @weapon_id
     @weapon_id = $game_party.actors[0].weapon_id
   end
   
   #if there's any battlers on map and player has a weapon
   #if @battlers > 0 && $game_party.actors[0].weapon_id > 0
   
   #if holding attack button
     if Input.press?(Input::Attack)
         @timer_1 += 1 unless @timer_1 == 24
         @sprite = '_charge_' + @type.to_s
         
         if @timer_1 == 24
           
           if Skill_Charges::Charge_Sprite == true
             @type = BlizzABS::Weapons.type($game_party.actors[0].weapon_id)
             $game_player.character_name_org = @original + @sprite
           end
           
           update_graphic
           @repeat = Skill_Charges::Repeat_Sound
           $game_system.running_button = false
           $game_player.normal_speed = BlizzABS::Config::SNEAK_SPEED
           @timer_2 += 1 unless @timer_2 == 65
           @play_se = true if @timer_2 == 64
           
           if @timer_1 == 24 && @timer_2 == 65 && @repeat == true
             Audio.se_play("Audio/SE/" + Skill_Charges::Sound_Effect, 80, 150)
             @timer_1 = 0
             
           elsif @play_se == true && @timer_2 == 65 && @repeat == false
             @play_se = false
             Audio.se_play("Audio/SE/" + Skill_Charges::Sound_Effect, 80, 150)
           end
           
         end
         
     #if attack is released before skill is ready.
     elsif !Input.press?(Input::Attack) && @timer_2 > 1 &&  @timer_2 <= 64
       
       if $game_player.character_name_org == @original + @sprite &&
         Skill_Charges::Charge_Sprite == true
          $game_player.character_name_org = @original - @sprite
        end
       
        $game_player.normal_speed = BlizzABS::Config::NORMAL_SPEED
         dispose
         
        #if attack is released when skill is ready.
       elsif !Input.press?(Input::Attack) && @timer_2 >= 64
         
         if $game_player.character_name_org == @original + @sprite &&
           Skill_Charges::Charge_Sprite == true
          $game_player.character_name_org = @original - @sprite
        end
       
        $game_player.normal_speed = BlizzABS::Config::NORMAL_SPEED
       dispose  
     end
     
 end
 def update_graphic
   
   if @timer_1 == 24
     @charge_hud = Sprite.new
     @charge_hud.bitmap = Bitmap.new(64,24)
     @charge_hud.bitmap.fill_rect(0,0,64,24,Color.new(0,0,0,255))
   end

 end
 def dispose
   if @charge_hud != nil
     p 'dispose'
     @charge_hud.bitmap.dispose
     @charge_hud.dispose
   end
   @timer_1 = 0
   @timer_2 = 0
  #
 end
end

class Scene_Map
 alias main_charge main; alias update_charge_later update
def main
   @charging = Charge_Skills.new
   main_charge
   @charging.dispose
 end
 
 def update
   update_charge_later
   @charging.update
 end
end


EDIT2: alright, I'll put up a small demo real fast give me one minute.

chaucer

just press and hold K to show the bitmap(top left corner) weird thing is, it's actually taking longer in the demo to disappear than it is in my project.

https://www.dropbox.com/s/4tuag49e85j8e4b/Bitmap_Dispose_Issue.rar?dl=0

KK20

February 20, 2015, 06:49:08 pm #6 Last Edit: February 20, 2015, 06:53:44 pm by KK20
Actually I figured it out. You're calling 'update_graphic' a bunch of times, which promptly creates Bitmap after Bitmap on top of each other without disposing the previous. So your dispose method is correct--you just need to make sure you're only drawing your stuff once.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

chaucer

oooh, wow that went over my head. I didnt even think about that, well, now I know where I messed up. Thanks for pointing that out bro, I did that in another script of mine too, I'll have to go back and fix that one as well now. Again, big thanks for the help.