MV - Unexpected token u in JSON at position 0

Hello,

One of my playtesters encountered this error and we've been unable to reproduce it. Google search hasn't yielded much besides that there might be a corrupted file somewhere.

I see the force action and ActorId mentioned, and I wonder if it's because I have an event early in this battle where some new actors join the party after the boss has a few force actions. However, my playtester mentioned this crash occurred ~10 turns after said event.

Posting here in hopes that someone knows what this error means. Thanks in advance.


error.png
The usual reason for this error message is that something has tried to pass undefined to JSON.parse. Based on the stack trace, it looks like something is trying to do Force Action on an actor, but BattleManager._action is undefined so YEP Battle Engine Core cannot memorise...hang on, I've seen this before. I'll go do a search~

👋 ...OK here's the thread:
Notably:
I came up with something that might solve the problem (just theory, I haven't tested it). Save the following code as a .js file (Save As > File Type: All Files, Filename: whateverYouLike.js), import as a plugin, and make sure to load it immediately after Battle Engine Core in the Plugin Manager~
Spoiler: A fix?
JavaScript:
// Place immediately below YEP_BattleEngineCore in the Plugin Manager

// Override - "no action" failsafe to avoid JSON.parse failure
BattleManager.setPreForceActionSettings = function() {
  return {
    subject: this._subject,
    action: this._action ? JsonEx.makeDeepCopy(this._action) : undefined,  // <- edit 1 of 1
    actionList: JsonEx.makeDeepCopy(this._actionList),
    targets: this._targets.slice(),
    allTargets: this._allTargets.slice(),
    indTargets: this._individualTargets.slice(),
    phaseSteps: JsonEx.makeDeepCopy(this._phaseSteps),
    returnPhase: this._returnPhase,
    phase: this._phase,
    conditionFlags: JsonEx.makeDeepCopy(this._conditionFlags),
    trueFlags: JsonEx.makeDeepCopy(this._trueFlags)
  }
};

// Override - do not restore "no action"
BattleManager.loadPreForceActionSettings = function() {
    var settings = this._forceActionQueue[0];
    if (settings) {
      this._forceActionQueue.shift();
      if (!settings.action) return false;  // <- edit 1 of 1
      this.resetPreForceActionSettings(settings);
      return this._subject && this._subject.isAppeared();
    } else {
      return false;
    }    
};
There are probably various things that can cause it, this "fix" treats the symptom, not the cause.
Thanks @caethyril , as usual you are a life saver 🙂 Based on the other thread that dev was probably having the same issue as me with a force action + stun effect. It's strange that I can't seem to replicate the error myself, but I will add this and hope it works.
You're welcome! (Hopefully it'll help.)

Original thread: https://forums.rpgmakerweb.com/threads/mv-unexpected-token-u-in-json-at-position-0.153078/