MV Game crashes when battle initiates during Show Choice window

I was working on my game, and noticed a bug that occurs when you trigger a battle while a show choice window is active.

TypeError: Cannot read property 'bitmap' of undefined

I first got this to trigger using Vlue's proximity events — with an enemy with a parallel process proximity sensor patrols around and triggers a battle when spotted. But I was able to recreate it in a completely fresh install with no plugins, using a parallel process that triggers a battle after a fixed time delay.

Installing Yanfly Core gives me a little more to work with...

TypeError: Cannot read property 'bitmap' of undefined
at Window_ChoiceList.get (rpg_core.js:6358:43)
at Window_ChoiceList.textWidthEx (rpg_windows.js:3908:42)
at Window_ChoiceList.maxChoiceWidth (rpg_windows.js:3899:32)
at Window_ChoiceList.windowWidth (rpg_windows.js:3875:22)
at Window_ChoiceList.Window_Command.initialize (rpg_windows.js:1302:22)
at Window_ChoiceList.initialize (rpg_windows.js:3827:41)
at new Window_ChoiceList (rpg_windows.js:3819:21)
at Window_Message.createSubWindows (rpg_windows.js:4275:26)
at Window_Message.initialize (rpg_windows.js:4252:10)
at new Window_Message (rpg_windows.js:4239:21)

This happens with no other plugins enabled.

I was not able to reproduce it with an event that triggers a battle on event touch. I was able to get the event to approach and even touch the player, but when a show choice window (or, for the matter, a show text window) is open then event touch events of any kind won't trigger.

I don't particularly want to discuss workarounds, I already made a plugin request thread here which would effectively circumvent the crash, and I've already redesigned it to prevent this from happening. But I'm kind of curious to see if anyone could explain what exactly is going on here and if it's fixable or not, because with how much I use time pressure in this game I feel like it could become an issue again.

I also wonder if anyone else has had a problem like this — because I couldn't find anything — and whether this remains unfixed for a reason or if it's just because it is a niche issue that nobody has ever really had before.
Installing Yanfly Core gives me a little more to work with...
Just as a note, you don't need a plugin for this - when the game crashes, press F8 and go to the Console tab and the full error trace is right there.

The error is saying your choice window doesn't have a contents bitmap property defined.

Aside from that, it would be guessing without you posting what the event actually looks like.
Oh, thanks for the F8 trick. I thought it was in there somewhere, just didn't remember where.

1.png



This is the event I have to get the choice window up. Basic as it gets.

3.png

This event has a custom move route to simulate a patrolling enemy. Using Vlue's proximity events, it will trigger a battle when it sees you. If the battle triggers while you're in the choice menu, the game instantly crashes.

I know I need a delay to prevent it from running every frame and causing lag. I had one originally but it didn't crash any less.

2.png

I tried reproducing it without plugins by changing EV002 into this and got the same results.
Without delving too deeply into it, I assume it's because one event has initiated the scene change and wiped all the data from the current map scene, but the other event is still running with a reference to a (now-deleted) choices window which it's trying to refresh.

The only fix I can think of for it is to block calls to change scenes while certain types of windows are open - which would probably cause undesirable behavior as you call Battle Processing and it simply doesn't work. Or perhaps you might iterate through anything in the interpreter when battle processing is called and shut it all down, which could also cause unintended effects someplace.

The easiest solution I can offer is if there's a possibility of this scenario coming up in a given map, do this instead:
The script call SceneManager._scene._messageWindow._choiceWindow.active will return true if the choices window is open. So you can put a loop into your battle-starting event to not call battle processing until that's not true:
1717289194125.png


This works perfectly for me.
Oh, that's a really good idea. I threw in another script call to get this:
cancel.png

...which will force cancel the prompt and initiate the battle. Thanks a lot, I that pretty much solves it.

I thought about making a plugin that does something like automatically this when a battle is initiating but that seems like overkill.
If you're going to force the player out of the choice, there's no point in putting it inside a loop.

That won't ever do anything more than once.

It's also worth mentioning that doesn't technically "force cancel the prompt" - it simulates the player pressing the cancel button. That means you have to have assigned a Cancel Choice in the event command for it to do anything at all.
1717346081611.png


If you want to go the route of forcing the player out of their conversation rather than waiting for them to choose, I think a better option would be
Code:
SceneManager._scene._messageWindow._choiceWindow.close()

That will close the window, which means your event won't be trying to refresh it causing the undefined bitmap errors.
The rpg maker script call list said it would cancel even if it's disabled but I just assumed it was true and never tested it, so thanks again.

It was set to a conditional originally but I completely misunderstood the point of the loop and included it for no reason so I'm grateful you cleared that up.
Okay, well, to be fair I also didn't test it.

Now that you've said that and I've looked at the code, it looks like it happens in a different order than I assumed it would - having Cancel Disabled in the event command blocks the actual input, as opposed to the input happening and it's told to do nothing.

So yes, calling the cancel directly like that will work fine for your purposes.
Yeah I got home and tested it and it seems to work even with no cancel option, so thanks for everything.

Original thread: https://forums.rpgmakerweb.com/threads/game-crashes-when-battle-initiates-during-show-choice-window.169193/