What is also important is that this set of circumstances doesn't always lead to a crash, only to the possibility of a crash. And the actual time of the crash seems to be mainly when a large amount of resources are shifted (eg., a scene switch), however, this is just speculation as this is not the case 100% of the time. AND if you don't crash within a few scene switches (and the error is not repeated), usually you won't at all. However, every single instance of a crash had, at some time close before it occurred, an instance of a Viewport being disposed without an associated Sprite (or Window, or Plane) and both being left without reference and at the mercy of the Ruby GC. I verified it with a pre-title loop where I created hundreds of Sprites and Viewports, disposing the viewports and leaving the sprites, until I found the minimum number that would trigger a crash (which was a single undisposed sprite). Granted, in order to trigger the crash reliably, I had to create and dispose a
bunch of sprites and expose the error on one of them, which is why I am so inclined to believe it is so linked to memory allocation.
I should also note that this issue seems to have been fixed in the implementation of RGSS3 (and I've never tested it in RGSS).
All things being equal and as frustrating as this error was for so many years to so many people, the simplest solution is just to not dispose Viewports and then leave around undisposed associated sprites with no reference. There is almost no practical reason to not dispose a sprite if you are going to dispose the Viewport (doing so renders it invisible), the only one I can think of is if you wanted to pass it another Viewport at a later point. However, the crash doesn't occur as long as there is a live reference to the Sprite, so I can think of *no* reason where you would want or need to do this.
On the flipside of, I've seen this error surface in several of the most popular battle systems for RPG Maker VX, including a version of Yanfly's Melody (if quick enough, you can exit before a fadeout effect has completed, which is linked directly to a sprite disposal), several versions of Tankentai (dummy actors the scene starts with are never disposed), Vlads SBABS (enemy HP bars are Scene specific, but are linked to a viewport in the Spriteset which is disposed on transferring to another map), and now a version of GTBS (victory condition sprite not being disposed when no longer needed). Because it doesn't have a 100% crash rate (some of these also only reached because of a specific set of circumstances) and because it doesn't throw an RGSSError immediately, I suspect very few even
know about the cause.
The best tool we have here is awareness - if you properly free your resources, you won't run into this problem. Not to disparage any of these other creators, who missed one object disposal in thousands of lines of code, in which no feedback is given to let you know that you have made that mistake. That is why I created that "debugger" script, which makes it very easy to identify which object is not being property disposed by tracking them all from their creation. I was hoping more scripters would pick it up, but with the timing (only a few weeks before the English release of ACE), I expect it is mostly being used as a workaround for "making old scripts work".
Anyway, enough rambling from me. If anyone wants to do some further testing, I've had good results replicating the crash with this:
http://pastebin.com/raw.php?i=23LNNhuS
@TDS
Viewport has no method by default where you can check all sprites associated with it (at least not one that can be determined with Ruby relection). You could add one accomplish this by modifying the initialize and viewport= method of Sprite (and Plane, Tilemap and Window), and to store back a representation (eg., its ID) of the Sprite in the Viewport. I found it easier to just track everything globally, so I could track the associated sprites
after the viewport was already disposed (which is when I was most interested in them in this case). Also note that the documentation is incorrect on a few instances here - Viewport#disposed? is not implemented, and the Plane viewport methods don't work how they are supposed to (see my debug script toward the bottom for my fixes for these). This is, of course, for RGSS2, in RGSS3 the Plane -viewport method issues have been fixed, though there is still no implementation of Viewport#disposed? like the manual says, and no method to check the associated sprites.
So since the original issue seems solved and we are straying a bit,
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.
I made an "official" sticky topic for the game.exe crashing issue causes/solutions where discussion on that can continue for anyone that is interested:
http://forums.rpgmak...needs-to-close/