GALV Event Spawner " TypeError: Cannot read property 'erase' of undefined"

RPG MAKER MV.
Game uses a transfer system that collaborates with a random event generator system.


When I transfer from a map to another, I erase all events, then create new ones.
I use the following script.


https://galvs-scripts.com/2016/05/14/mv-event-spawner/

Conslole returns this:

Spoiler: Console Returns this
(FILE PATHS ARE EDITED)

TypeError: Cannot read property 'erase' of undefined
at Game_Map.eraseEvent (file:///C/js/rpg_objects.js:5570:26)
at Game_Interpreter.command214 (file:///C/js/rpg_objects.js:9826:18)
at Game_Interpreter.executeCommand (file:///C://js/rpg_objects.js:8930:34)
at Game_Interpreter.update (file:////js/rpg_objects.js:8838:19)
at Game_SpawnEvent.Game_Event.updateParallel (file:///...../js/rpg_objects.js:8748:27)
at Game_SpawnEvent.Game_Event.update (file:///..../js/rpg_objects.js:8740:10)
at file:///C:/......./js/rpg_objects.js:6066:15
at Array.forEach (native)
at Game_Map.updateEvents (file:......./js/rpg_objects.js:6065:19)
at Game_Map.update (file:///C:/Users/....../js/rpg_objects.js:6025:10)rpg_managers.js:1949 SceneManager.catchException


Where shall I look for something I blew?
Most important, what does the console say about it?
Looks like you tried to erase an event that already was erased earlier.

So it's either an index problem of the loop you made to erase events, or you accidentally gave two erase commands on the same event.
Makes sense to me. It's exactly what I thought but I am not sure why it happens.
I mean if the object is destroyed before another destroyer comes it makes sense to throw an exception because of the existing object, but how I actually managed to do that?
Is it possible the event to be erased by itself (Parallel Proccess erasing the event) so the plugin command cant find it in time?
I am gonna investigate what might gone wrong, and thanks for pointing me out on that direction. Time to dive into the whole thing!
It would really hell if you showed us what you did, screenshots of how the events for erasing and creating events look like instead of only describing the error itself...
Thanks @Andar but it seems I found out what was happening.

So people listen up.
If you involve a LOT of events spawning, and all of these happen using a randomizing system, well things might need some time to happen.
So if you put a delay (wait 60 for example) between room transfers, there will not be any problem again. That is how I solved it, I am testing for 15 minutes and it is rock solid.
I won't request the thread to close yet until I will make sure it works 100%.

It seemed to work... the random crash occured again, but I now can guess what is going on.
In vx ace you could insert a conditional branch before deleting the event id.
if event id != nil
than do delete stuff
else nothing skip to next id whatever.
Thatway the game would not crash even if the id does not exist.
Iam a script noob and have no real clue if this maybe helps in this case.
I think I used badly the script.
I rewrote all commands and it works way more solid (didn't found a simple bug) but now something else is somewhat broken. Nothing I can't fix though and its an easy fix. Bath time though... 😛

Original thread: https://forums.rpgmakerweb.com/threads/galv-event-spawner-typeerror-cannot-read-property-erase-of-undefined.86295/