Exception in dispose_all_Windows?

Status
Not open for further replies.
Joined
Jul 17, 2017
Messages
41
Reaction score
3
First Language
Spanish
Primarily Uses
RMVXA
Hi everyone, lately I've been creating custom scenes and windows to show variables and other parameters.

but I have a problem, it turns out that I created a window in Scene_Map and this window is always on screen (on the map) because it refreshes constantly.

but, when calling another scene, this window disappears, and it is because by default in Scene_Base, it defines that when a scene ends, it deletes all the windows so that another scene is shown.
can be seen in "Scene_Base" line 61:

zxzzz436095.png


I was watching a little more and it turns out that the Scene_Base deletes all the variables that start with "Window" to massively delete the windows when the scene changes, you can see this in "Scene_Base" line 101:

zxzzz436094.png

Is there a way to make an exception so that a specific window so that it is not deleted in this process?
And in that case, can you make an exception more than one window?


I was reading the content manual, but it hasn't given me an answer.

in advance, I really appreciate the help.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
Yeah and nope.

You see, everything is possible, but that's a terrible idea. Windows should always be disposed of!

You don't want your game to suffer from memory leaks and weird floating windows and sprites showing up where they shouldn't, right?
 
Joined
Jul 17, 2017
Messages
41
Reaction score
3
First Language
Spanish
Primarily Uses
RMVXA
Yeah and nope.

You see, everything is possible, but that's a terrible idea. Windows should always be disposed of!

You don't want your game to suffer from memory leaks and weird floating windows and sprites showing up where they shouldn't, right?
Scene switching removes windows, but returning to the same scene makes them appear again.
I just want certain windows not to be removed in changing scenes.

In addition, each window has its individual "dispose" if one defines it, so there would be no problems in that mode.
there are many ways to hide windows to avoid consuming performance.

I just want an exception.
like this example:

Ruby:
 def dispose_all_windows
     instance_variables.each do |varname|
       ivar = instance_variable_get (varname)
       ivar.dispose if ivar.is_a? (Window) except Window_Example && Window_Example2
     end
   end
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
285
Reaction score
70
First Language
English
Primarily Uses
RMXP
The best way to ensure there won't be a memory leak is to dispose of them. Any other strategy is risky.

There's nothing bad in defining the same window in 2 different scenes, no matter if they switch between them by pressing any button or not.

The only alternative would be to mix both scenes into a single one with extra conditions to define when a given window should show up or not.

An invisible window is still a window loaded into memory so not properly disposed of at the end of a scene is always a problem. Hiding it doesn't solve your issue, it'd only be a hack programmers should advice against.
 

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
I just want an exception.
like this example:

Ruby:
 def dispose_all_windows
     instance_variables.each do |varname|
       ivar = instance_variable_get (varname)
       ivar.dispose if ivar.is_a? (Window) except Window_Example && Window_Example2
     end
   end
I don't know much (if anything) about memory lag and it sounds scary (plus Kyonides seems to know his/her stuff), so maybe best not to do this if it'll muck things up...

But!

If you're just looking for how to write that line you used as an example in Ruby / RGSS3, then I think all you'd need to do is write it like this:

ivar.dispose if ivar.is_a?(Window) unless ivar == Window_Example || Window_Example2

Theoretically... I think.
Haven't tested it, haven't dabbled much in window disposal, but pretty sure that code should work.
 
Joined
Jul 17, 2017
Messages
41
Reaction score
3
First Language
Spanish
Primarily Uses
RMVXA
I don't know much (if anything) about memory lag and it sounds scary (plus Kyonides seems to know his/her stuff), so maybe best not to do this if it'll muck things up...

But!

If you're just looking for how to write that line you used as an example in Ruby / RGSS3, then I think all you'd need to do is write it like this:

ivar.dispose if ivar.is_a?(Window) unless ivar == Window_Example || Window_Example2

Theoretically... I think.
Haven't tested it, haven't dabbled much in window disposal, but pretty sure that code should work.
I really appreciate the help, but it doesn't solve my problem...
that code only causes that when the windows "Window_Example" and "Window_Example2" are shown, command dispose_all_window does not delete any window in scene. and it's not the idea, the idea is for the command to delete all windows except the ones mentioned.
 

Xane

Veteran
Veteran
Joined
Jun 5, 2020
Messages
66
Reaction score
326
First Language
(US) English
Primarily Uses
RMVXA
Here, I don't know how well you know your RGSS but here's a quick little hack.
Ruby:
class Scene_Base
 
  # It's not pretty for neat code but this will let you carry the window
  # to every scene minus the scenes listed below. This will also retain
  # the dispose function otherwise you end up with nasty garbage collection.
  # You should always dispose your windows regardless.
 
  alias :xane_window_keeper_start :start
 
  def start
    xane_window_keeper_start
    create_my_keeper_windows
  end
 
  def create_my_keeper_windows
    return if SceneManager.scene_is?(Scene_Title)
    return if SceneManager.scene_is?(Scene_Battle)
    return if SceneManager.scene_is?(Scene_Save)
    return if SceneManager.scene_is?(Scene_Load)
    # You can refrence this window by using the variable @custom_window
    @custom_window = nil # Your window class name here.
  end
end
No matter what you should always dispose of your Window Classes. You'll create a bad memory leak otherwise and end up with a major headache down the line that you can't track down.
 

The_Sarah

Let's make great games together!
Veteran
Joined
Jul 18, 2020
Messages
100
Reaction score
79
First Language
English
Primarily Uses
RMVXA
I really appreciate the help, but it doesn't solve my problem...
that code only causes that when the windows "Window_Example" and "Window_Example2" are shown, command dispose_all_window does not delete any window in scene. and it's not the idea, the idea is for the command to delete all windows except the ones mentioned.
Ah, I was worried that would happen.
Yeah sorry, out of my wheelhouse a bit for now then, thankfully others are here to help (like Xane and Kyonides).
 
Joined
Jul 17, 2017
Messages
41
Reaction score
3
First Language
Spanish
Primarily Uses
RMVXA
Ah, I was worried that would happen.
Yeah sorry, out of my wheelhouse a bit for now then, thankfully others are here to help (like Xane and Kyonides).
Don't worry, also using the code that you have provided will be useful for other things, so thanks also c:
 
Joined
Jul 17, 2017
Messages
41
Reaction score
3
First Language
Spanish
Primarily Uses
RMVXA
Here, I don't know how well you know your RGSS but here's a quick little hack.
Ruby:
class Scene_Base

  # It's not pretty for neat code but this will let you carry the window
  # to every scene minus the scenes listed below. This will also retain
  # the dispose function otherwise you end up with nasty garbage collection.
  # You should always dispose your windows regardless.

  alias :xane_window_keeper_start :start

  def start
    xane_window_keeper_start
    create_my_keeper_windows
  end

  def create_my_keeper_windows
    return if SceneManager.scene_is?(Scene_Title)
    return if SceneManager.scene_is?(Scene_Battle)
    return if SceneManager.scene_is?(Scene_Save)
    return if SceneManager.scene_is?(Scene_Load)
    # You can refrence this window by using the variable @custom_window
    @custom_window = nil # Your window class name here.
  end
end
No matter what you should always dispose of your Window Classes. You'll create a bad memory leak otherwise and end up with a major headache down the line that you can't track down.
It works perfectly!
Thanks for the help! c:
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,573
Reaction score
6,496
First Language
Indonesian
Primarily Uses
RMVXA
There is one solution to avoid memory leak and keep the window.
The memory leak happens when there is no variable that references to the window.

The memory leak happens when you do this
Code:
@my_window = Window_Base.new(1,1,100,00)
@my_window = nil
Since it loses its reference, you will still able to see the window is there, but you can not access it. You can not dispose it. It stuck there in the game without you not being able to do something about it. This is why the Scene_Base take care of it.

Now, if you make an exception in dispose all window method, your window will lose its reference. It will create stacks of an undisposed window that loses its reference. Eventually, build up stack and memory leak that causes a crash. Please mind this before proceeding further.

However, the method to dispose all windows is not perfect.
if you store your windows in an array, the dispose all window method will not detect your window because the variable will be recognized as an array, not Window.

If you store your Window in a global variable, i.e,
Code:
$my_window = Window_Base.new(1,1,100,100)
It will not be disposed as well. And it will not create a memory leak as long as you never change the $my_window variable. You don't even need to change the dispose all window method if you're going this way.
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,137
Reaction score
8,418
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Shade the Mystic wrote on YouFulca's profile.
I just wanted to drop you a line to tell you that you are flipping amazing. I've listened to a few RM composers over the years, and while they all had their strengths, yours is the only work I'd dare call memorable. I honestly don't think I've heard such amazing RM scores outside of Yasunori Mitsuda, no joke. Keep up the amazing work!
Seamless secret passages just by painting a path with a region id. Simple but slick.
Playing with colour ramps. The first set is the originals, the ones only facing forward in different colour schemes are the new colours.

I present... MAGIC (in progress)

Forum statistics

Threads
102,981
Messages
996,452
Members
134,447
Latest member
Smashbroly
Top