An issue with the scene interpreter was reported 6 months ago by a member of the RPGMakerWeb community, Sixth, in the comments section for Scene Interpreter. Unfortunately, the report went unnoticed on my part and the issue continued to persist.
I have implemented a fix offered by Mithran for now. If possible, please update the script. I apologize for the inconvenience this may have caused for anyone that has used this script in their releases.
Below is an explanation of the problem and how it (probably) happened, as I don’t exactly remember the decisions that were being made when I originally wrote the script.
The Message Problem
It all begins with the creation of message windows.
The scene interpreter’s role is to allow you to basically run common events in any scene by creating a comment and writing
<run scene: current>
So for example, let’s say you used an item from the item menu, and the item called a common event. By default, the item menu would close and you would go back to the map, where the common event would execute. By using this script, the common event would execute directly in the item menu.
Most event commands work fine, but a number of commands did not because they relied on things that may not exist in the current scene. In particular, messages weren’t shown in scenes because there just wasn’t a message window available for the scene.
Introducing a “Scene Message Window”
My solution was to create a message window for every scene. Seems simple enough: whenever a scene starts up, just create a message window. Now you can just run your common event, and if text needs to be displayed, the scene’s message window will go ahead and read it.
One problem I ran into was that when you showed messages on the map, a duplicate message would be shown. So you would run an event, and a message would be displayed. Once you close the message window, you’ll see another message window underneath it.
I then realized two message windows were being created: one of them was the “scene message window”, and the other is the default message window that the map was creating already.
I think what happened here is I decided to simply define the message window the same way as the ones found in Scene_Map and Scene_Battle
def create_message_window @message_window = Window_SceneMessage.new end
So our message windows are still being created twice, but the second time it’s created, it will simply replace the old one and carry on with that.
Of course, that assumption was wrong. While the reference to the old message window was lost, it was not properly disposed. Over-time, more and more of these old message windows started to accumulate, consuming more memory.
Eventually, as some developers have found out, the performance of their game became very sluggish over-time since the game could not get rid of all these message windows.
Fixing the Leak
At this point, I have not figured out a proper way to address the issue. The solution offered by Mithran was to avoid replacing the reference:
class Scene_Map def create_message_window @message_window = Window_Message.new unless @message_window && !@message_window.disposed? end end class Scene_Battle def create_message_window @message_window = Window_Message.new unless @message_window && !@message_window.disposed? end end
This would take care of the issue for the map scene and battle scene, but if you have any other scenes that are also creating message windows, the issue would occur again.
Evidently, the decision to resolve the duplicate message window issue by simply “replacing” it and hoping the game would clean up the reference was wrong and the consequences are devastating.