Disposed window error

For a game I'm working on, I have certain menu commands (in this case the Item command) in Scene_Menu open up other command windows with their own choices (which will be referred to in the rest of my question as sub-command windows. I'm having this problem where if I go to a scene from a command on a sub-command window, the game crashes when I return to Scene_Menu with the error 'disposed window'. I have also tested the code in a seperate project with the default scripts and had the same error. Can someone please help?


Here is my source code:

Spoiler
class Window_MenuItem < Window_Command
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0)
    update_placement
    self.openness = 0
    open
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return 160
  end
  #--------------------------------------------------------------------------
  # * Update Window Position
  #--------------------------------------------------------------------------
  def update_placement
    self.x = (Graphics.width - width) / 2
    self.y = (Graphics.height - height) / 2
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_command("Party",         😛arty)
    add_command("Actor",         :actor)
    add_command(Vocab::cancel,   :cancel)
  end
end
class Scene_Menu
  #--------------------------------------------------------------------------
  # * Create Item Window
  #--------------------------------------------------------------------------
  def create_item_window
    @item_window = Window_MenuItem.new
    @item_window.x = 0
    @item_window.y = 216
    @item_window.set_handler🙂party,     method🙂command_party_items))
    @item_window.set_handler🙂actor,     method🙂command_personal))
    @item_window.set_handler🙂cancel,    method🙂on_item_close))
  end
  #--------------------------------------------------------------------------
  # * Close Item Window
  #--------------------------------------------------------------------------
  def close_item_window
    @item_window.close
    update until @item_window.close?
  end
  #--------------------------------------------------------------------------
  # * Item Window Cancel Handling
  #--------------------------------------------------------------------------
  def on_item_close
    @item_window.unselect
    @command_window.activate
    close_item_window
  end
  #--------------------------------------------------------------------------
  # * [Item] Command On Command Window
  #--------------------------------------------------------------------------
  def command_item
    create_item_window
  end
  #--------------------------------------------------------------------------
  # * [Party] Command On Item Window
  #--------------------------------------------------------------------------
  def command_party_items
    SceneManager.call(Scene_Item)
  end
end

Thank you.
The problem lies where you're creating the window. It's being created too late inside the class and has nothing to reference when the scene returns back to the main menu. It's a simple fix. Give me a second to write it out. I'll edit this post with the fix after.


Edit: So I went back and cleaned everything up for you so it's more efficient as well and I also fixed a couple of extra problems I saw you would have had down the line. Here is the fix. I also wrote a comment inside the code for you to place your methods for your actor command option. It's located in the on_personal_ok def.

Spoiler
#==============================================================================
# ** Kazama - Item Window Choice Fix
#    Commissioned for Jono99
#    Version 1.0
#------------------------------------------------------------------------------
#  Placement:
#  Place this script under Materials.
#------------------------------------------------------------------------------
#  License:
#  None.
#==============================================================================


#==============================================================================
# ** Window_MenuItemPrompt
#------------------------------------------------------------------------------
#  This window displays a choice upon selecting the item command.
#==============================================================================


class Window_MenuItemPrompt < Window_Command
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize
        super(0, 216)
        self.openness = 0
    end
    #--------------------------------------------------------------------------
    # * Create Command List
    #--------------------------------------------------------------------------
    def make_command_list
        add_command("Party", 😛arty_items)
        add_command("Actor", :actor_items)
    end
end


#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs the menu screen processing.
#==============================================================================


class Scene_Menu < Scene_MenuBase
    #--------------------------------------------------------------------------
    # * Alias Listings
    #--------------------------------------------------------------------------
    alias :kazama_item_window_choice_fix_scene_menu_start      :start
    alias :kazama_item_choice_fix_scene_menu_on_personal_ok    😮n_personal_ok
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
      kazama_item_window_choice_fix_scene_menu_start
      create_item_prompt_window
  end
  #--------------------------------------------------------------------------
  # * Create Item Prompt Window
  #--------------------------------------------------------------------------
  def create_item_prompt_window
      @item_prompt_window = Window_MenuItemPrompt.new
      @item_prompt_window.viewport = @viewport
      @item_prompt_window.set_handler🙂party_items, method🙂on_party_command))
      @item_prompt_window.set_handler🙂actor_items, method🙂on_actor_command))
      @item_prompt_window.set_handler🙂cancel, method🙂on_cancel_command))
  end
  #--------------------------------------------------------------------------
  # * [Item] Command
  #--------------------------------------------------------------------------
  def command_item
      @item_prompt_window.open.activate.select(0)
  end
  #--------------------------------------------------------------------------
  # * [On Party] Command
  #--------------------------------------------------------------------------
  def on_party_command
      SceneManager.call(Scene_Item)
  end
  #--------------------------------------------------------------------------
  # * [On Actor] Command
  #--------------------------------------------------------------------------
  def on_actor_command
      @item_prompt_window.deactivate
      command_personal
  end
  #--------------------------------------------------------------------------
  # * [On Cancel] Command
  #--------------------------------------------------------------------------
  def on_cancel_command
      @item_prompt_window.close
      update until @item_prompt_window.close?
      @command_window.activate
  end
  #--------------------------------------------------------------------------
  # * [OK] Personal Command
  #--------------------------------------------------------------------------
  def on_personal_ok
    case kazama_item_choice_fix_scene_menu_on_personal_ok
    when :item_prompt
        # Your Custom Data goes Here Jono99
    end
  end
  #--------------------------------------------------------------------------
  # * [Cancel] Personal Command
  #   Warning : Overwritten Method
  #--------------------------------------------------------------------------
  def on_personal_cancel
    @status_window.unselect
    @item_prompt_window.open? ? @item_prompt_window.activate : @command_window.activate
  end
end
 
The problem lies where you're creating the window. It's being created too late inside the class and has nothing to reference when the scene returns back to the main menu. It's a simple fix. Give me a second to write it out. I'll edit this post with the fix after.


Edit: So I went back and cleaned everything up for you so it's more efficient as well and I also fixed a couple of extra problems I saw you would have had down the line. Here is the fix. I also wrote a comment inside the code for you to place your methods for your actor command option. It's located in the on_personal_ok def.

Spoiler
#==============================================================================
# ** Kazama - Item Window Choice Fix
#    Commissioned for Jono99
#    Version 1.0
#------------------------------------------------------------------------------
#  Placement:
#  Place this script under Materials.
#------------------------------------------------------------------------------
#  License:
#  None.
#==============================================================================


#==============================================================================
# ** Window_MenuItemPrompt
#------------------------------------------------------------------------------
#  This window displays a choice upon selecting the item command.
#==============================================================================


class Window_MenuItemPrompt < Window_Command
    #--------------------------------------------------------------------------
    # * Object Initialization
    #--------------------------------------------------------------------------
    def initialize
        super(0, 216)
        self.openness = 0
    end
    #--------------------------------------------------------------------------
    # * Create Command List
    #--------------------------------------------------------------------------
    def make_command_list
        add_command("Party", 😛arty_items)
        add_command("Actor", :actor_items)
    end
end


#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs the menu screen processing.
#==============================================================================


class Scene_Menu < Scene_MenuBase
    #--------------------------------------------------------------------------
    # * Alias Listings
    #--------------------------------------------------------------------------
    alias :kazama_item_window_choice_fix_scene_menu_start      :start
    alias :kazama_item_choice_fix_scene_menu_on_personal_ok    😮n_personal_ok
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
      kazama_item_window_choice_fix_scene_menu_start
      create_item_prompt_window
  end
  #--------------------------------------------------------------------------
  # * Create Item Prompt Window
  #--------------------------------------------------------------------------
  def create_item_prompt_window
      @item_prompt_window = Window_MenuItemPrompt.new
      @item_prompt_window.viewport = @viewport
      @item_prompt_window.set_handler🙂party_items, method🙂on_party_command))
      @item_prompt_window.set_handler🙂actor_items, method🙂on_actor_command))
      @item_prompt_window.set_handler🙂cancel, method🙂on_cancel_command))
  end
  #--------------------------------------------------------------------------
  # * [Item] Command
  #--------------------------------------------------------------------------
  def command_item
      @item_prompt_window.open.activate.select(0)
  end
  #--------------------------------------------------------------------------
  # * [On Party] Command
  #--------------------------------------------------------------------------
  def on_party_command
      SceneManager.call(Scene_Item)
  end
  #--------------------------------------------------------------------------
  # * [On Actor] Command
  #--------------------------------------------------------------------------
  def on_actor_command
      @item_prompt_window.deactivate
      command_personal
  end
  #--------------------------------------------------------------------------
  # * [On Cancel] Command
  #--------------------------------------------------------------------------
  def on_cancel_command
      @item_prompt_window.close
      update until @item_prompt_window.close?
      @command_window.activate
  end
  #--------------------------------------------------------------------------
  # * [OK] Personal Command
  #--------------------------------------------------------------------------
  def on_personal_ok
    case kazama_item_choice_fix_scene_menu_on_personal_ok
    when :item_prompt
        # Your Custom Data goes Here Jono99
    end
  end
  #--------------------------------------------------------------------------
  # * [Cancel] Personal Command
  #   Warning : Overwritten Method
  #--------------------------------------------------------------------------
  def on_personal_cancel
    @status_window.unselect
    @item_prompt_window.open? ? @item_prompt_window.activate : @command_window.activate
  end
end
 

Thank you so much! I feel so honoured that you went out of your way to give me such a detailed answer to my question. I already knew how to add scene calls to on_personal_ok, so you didn't have to do that, but thank you regardless (although, when I tried it, the on_personal_ok didn't work). You are going into the credits as we speak! Also, I'll message you a link to the game once the next update's out.
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.

Original thread: https://forums.rpgmakerweb.com/threads/disposed-window-error.68962/