The game crashes after a battle is over.

Well, doing that we now returned to the state were the sound is gone after the battle, but without commenting out line 77 in BattleManager.

After the battle, this appears in the console.

Code:
BGM -> name:Testmusic volume:50 pitch:100 pos:264608

It looks like the game's running the music, but in reality nothing's actually coming out.
I tried that with the 'Auto-Change BGM' in the map properties and making an event for it to play it. The results were the same.
Fun thing: If I escape the battle, the battle BGM continues playing, but not the actual map BGM.
Could you please do a global search (control + shift + f) for the following?

RPG::BGM

and let us know what comes up?


Odd ... RPG::BGM is defined as this:
Code:
class RPG::BGM < RPG::AudioFile
  @@last = RPG::BGM.new
  def play(pos = 0)
   if @name.empty?
     Audio.bgm_stop
     @@last = RPG::BGM.new
   else
     Audio.bgm_play('Audio/BGM/' + @name, @volume, @pitch, pos)
     @@last = self.clone
   end
  end
  def replay
   play(@pos)
  end
  def self.stop
   Audio.bgm_stop
   @@last = RPG::BGM.new
  end
  def self.fade(time)
   Audio.bgm_fade(time)
   @@last = RPG::BGM.new
  end
  def self.last
   @@last.pos = Audio.bgm_pos
   @@last
  end
  attr_accessor :pos
end

Note in the replay method, it calls play, passing @pos. But where is @pos defined? It's not a property of RPG::BGM, RPG::AudioFile, or Object. The pos passed into the play method is not saved anywhere.


OP, could you please try to add this in a new script slot right at the bottom?
Code:
class RPG::BGM < RPG::AudioFile
  def replay
    play(last)
  end
end

You will need to set your scripts back to the point where it tries to play the map bgm but was crashing.

I hope you made a copy of your scripts file before starting to make changes, because there have been a lot of random changes that were just for troubleshooting purposes suggested in this thread, and you will need to go through and remove them (and also undo the changes that didn't work).
@CarlosDavilla Hmm, I kind of expected a bit more information from the console than the BGM line. And yeah, since we commented out line 18 in that BGM script I posted, the BGM is not being re-played. And if there was no error after commenting out line 77 in BattleManager, then replaying both BGM and BGS cause the error. There must be some script that is tinkering with both BGM and BGS.

EDIT: You can delete the BGM script that I posted from your project. And un-comment line 77 and 78 in BattleManager.

EDIT II: @Shaz 'pos' is set via the 'attr_accessor : pos' line near the end of RPG::BGM
Hmm, I kind of expected a bit more information from the console than the BGM line.

Code:
["{0007}:77:in `replay_bgm_and_bgs'", "{0150}:386:in `process_victory'", "{0007}:194:in `judge_win_loss'", "{0117}:520:in `process_event'", "{0117}:47:in `update'", "{0152}:410:in `update'", "{0100}:14:in `main'", "{0006}:23:in `run'", "{0222}:446:in `run'", "{0229}:10:in `block in <main>'", ":1:in `block in rgss_main'", ":1:in `loop'", ":1:in `rgss_main'", "{0229}:8:in `<main>'", "ruby:in `eval'"]

[]

BGM -> name:Musictest volume:50 pitch:100 pos:132304

This is all that appears besides before the BGM line that I posted before. It doesn't CTD or anything, so no errors show up.

Could you please do a global search (control + shift + f) for the following?

RPG::BGM

and let us know what comes up?

That's what shows up, @Shaz:

dV9xFWw.png
@CarlosDavilla Hmm ... well, the answer is probably tucked away in one of the scripts that tinker with the BGM class. Unfortunately, I need to head to bed for now. If this is not solved tomorrow, I will take another peek at some of those scripts. Remember to remove that BGM script I posted from your project and un-comment line 77 and 78 in BattleManager so that the error will show up again.
@Ossra thanks for that - missed it completely!

@CarlosDavilla what is the unnamed script right at the bottom? Look at all your empty script slots, and any that actually do contain scripts, please hame them.

Now, do you have all the script changes from this thread undone, so you are back to stage 1 - crashing when ending a battle? Once you get there, could you please disable the following scripts, and try again?

Galv's Basic Music Player
Hime's Music Mute Switch
CSCA Autosave Plus
Kazama's Blackjack
and the last one if you still have it (guessing it might be one of the scripts from this thread).

To disable a script, go into it, and search for ==BEGIN - if you don't find that, then you can just put ==BEGIN right at the top of the script, on its own line, and ==END right at the bottom, on its own line, making sure they both start as close to the left as possible.
what is the unnamed script right at the bottom? Look at all your empty script slots, and any that actually do contain scripts, please hame them.

Now, do you have all the script changes from this thread undone, so you are back to stage 1 - crashing when ending a battle? Once you get there, could you please disable the following scripts, and try again?

The unamed ones belonged to Ossra's script that tried to fix the issue before. When I deleted it, the ones that appeared in the bottom of the search were gone.
I always identify my scripts by author and official name because I have a REALLY BAD memory spam.

And well, I removed the said scripts, and it looks like I found the responsible.
Hime's Music Mute Switch.
Now the battle ends and the map BGM plays as normal. If I escape the battle as well.
So, that's the end of that, I suppose.
This thread can now be closed?

@CarlosDavilla Hmm ... well, the answer is probably tucked away in one of the scripts that tinker with the BGM class. Unfortunately, I need to head to bed for now. If this is not solved tomorrow, I will take another peek at some of those scripts. Remember to remove that BGM script I posted from your project and un-comment line 77 and 78 in BattleManager so that the error will show up again.

Looks like the issue was solved, @Ossra
But it's okay, thank you for your help either way. I really appreciate the effort you put on trying to solve my issue.
Sleep well and have a good day, will ya'?

Thanks for the help, guys. If I need some assistance with this again, I'll inform you.
Cheers.
So, that's the end of that, I suppose.
This thread can now be closed?
Well, only if you don't want to use that script 🙂

The first step to solving the problem is to determine what script is causing it. The second step is fixing the problem.

Just to confirm we have step 1, if you enable all the other scripts again except that one, does it work as it should? And when you also enable that script, it crashes again? (Note, I didn't want you to remove the scripts - I only wanted you to disable them - I'm assuming that's what you did, so enabling them should be as simple as removing those lines you added to each one).

If if works when just that script is disabled, but not when it's enabled again, please provide a link to the script and we'll take a closer look at it.

(and btw - if this IS the issue, I want to note that Ossra did an amazing job of troubleshooting. I learned a few new things in there, and there are some things I don't understand in that script that I now need to learn 😀 )
The first step to solving the problem is to determine what script is causing it. The second step is fixing the problem.

Well, I actually want to use that script, but if a script doesn't work well with the ones I already have, I usually just have it discarded.
Don't I have to make another post in Script Requests in order to ask for script fixes?
Besides, I already requested to close the thread, so...

Just to confirm we have step 1, if you enable all the other scripts again except that one, does it work as it should? And when you also enable that script, it crashes again?

Yes, that was issue. I ran the game out with the other ones (and for some reason my game cannot live without CSCA Autosave Plus so much it crashes on the title screen, but nevermind that) and it worked just fine. I put back in and it crashed again.

If so, please provide a link to that script and we'll take a closer look at it.

Sure, here you go.
Don't I have to make another post in Script Requests in order to ask for script fixes?
No, you can just report the thread and ask the mods to move it to the correct place (which would be RGSS3 Script Support)


In that script, can you try replacing the following two methods:
Code:
  class RPG::BGM   
   alias :th_music_mute_switch_play :play
   def play
     return if $game_system.mute_copyright? && TH::Music_Mute_Switch::Mute_List.include?(@name)
     th_music_mute_switch_play
   end
  end
 
  class RPG::BGS
   alias :th_music_mute_switch_play :play
   def play
     return if $game_system.mute_copyright? && TH::Music_Mute_Switch::Mute_List.include?(@name)
     th_music_mute_switch_play
   end
  end

with this instead?
Code:
  class RPG::BGM   
   alias :th_music_mute_switch_play :play
   def play(pos = 0)
     return if $game_system.mute_copyright? && TH::Music_Mute_Switch::Mute_List.include?(@name)
     th_music_mute_switch_play(pos)
   end
  end
 
  class RPG::BGS
   alias :th_music_mute_switch_play :play
   def play(pos = 0)
     return if $game_system.mute_copyright? && TH::Music_Mute_Switch::Mute_List.include?(@name)
     th_music_mute_switch_play(pos)
   end
  end

and see if it makes a difference? And of course re-enable the script if you haven't done so already.
Thread closed IgnoreMe As requested by the OP.
Moderator note: Reopening this for further help and clarifications.
Closing once again (the member who requested re-opening it has agreed it can be closed).

I'm glad that Shaz's solution worked for you!

Original thread: https://forums.rpgmakerweb.com/threads/the-game-crashes-after-a-battle-is-over.113626/