Scene_File FIX

Scene_File FIX

by Kyonides
​

Introduction

Scripts like GOBJ try to catch weird stuff the RM engine does when creating visual objects or disposing of them, but I think it's a terrible approach because they simply ignore the bugs already contained in the default scripts.

Yes, I know that VX ACE includes 2 bug fixes by default nowadays. Still, they're not all inclusive at all. There's one potential issue that has been ignored for quite a long time: the disposal of a Viewport object BEFORE its children have been disposed. Those children objects include Sprites and Windows. A perfect example of this is the Scene_File class, the parent class of Scene_Save and Scene_Load.

In the default script you can find the terminate method that says:

Ruby:
  def terminate
    super
    @savefile_viewport.dispose
    @savefile_windows.each {|window| window.dispose }
  end

That means that the Scene_File class and its children classes are disposing of the Viewport right before it takes care of the Savefile windows. A bad choice indeed. It should always followed the opposite order.

[EDITED] Get rid of:
  1. The children objects first
  2. Then dispose of the parent object safely.

How can you fix it?

Well, the solution is QUITE SIMPLE: just invert the order in which those objects get disposed of, and that's it. So you'd only need to paste the following code in the bug fix section of the Script Editor and you'll be fine:

Ruby:
# * Scene_File FIX * #

class Scene_File
  def terminate
    super
    @savefile_windows.each {|window| window.dispose }
    @savefile_viewport.dispose
  end
end

Why is this fix relatively important for you as a game developer?

It might not look impressive or critical at all, yet, it's highly convenient to prevent the engine from trying to do stuff in the incorrect / not-so-logical order in the first place. Debugger scripts like GOBJ will try to catch all those windows or their custom contents as critical objects that need to be notified otherwise.

Terms & Conditions

None.
Thank you so much for this!
Is Scene_File the only case among the base classes where this behavior occurs?
I’m currently not at home and can’t check myself, so I was wondering how many scenes actually use viewports and how or where they get disposed of. Since Scene_File disposes of it manually, I’m guessing Scene_Base doesn’t contain any logic for automatically disposing of viewports like it does for windows.
I’m curious about this because I’m planning to do a debug run with GOBJ on all of my custom scripts that I’ll be releasing soon.
Hello, by default Scene_Base dispose of all windows attributes before removing its viewport (called@viewport).
The only other scenes introducing other viewports are Scene_Battle with @info_viewport and Scene_File and its children. Scene_Base already delete all windows before getting rid of the main viewport while Scene_Battle get rid of its viewport after calling Scene_Base's termination.
Scne_File seems to be the only exception with the dispose order issue as it is the only one with an array of windows as an attribute (hence the need to remove them explicitly).

You might also want to check the Spriteset classes as they also deal with viewports and sprite disposal, though none of the base class have a bug in their dispose order from what I've seen.
Hello, by default Scene_Base dispose of all windows attributes before removing its viewport (called@viewport).
The only other scenes introducing other viewports are Scene_Battle with @info_viewport and Scene_File and its children. Scene_Base already delete all windows before getting rid of the main viewport while Scene_Battle get rid of its viewport after calling Scene_Base's termination.
Scne_File seems to be the only exception with the dispose order issue as it is the only one with an array of windows as an attribute (hence the need to remove them explicitly).

You might also want to check the Spriteset classes as they also deal with viewports and sprite disposal, though none of the base class have a bug in their dispose order from what I've seen.
Thanks! Then i'm probably fine.

Original thread: https://forums.rpgmakerweb.com/threads/scene_file-fix.180523/