Page 1 of 1

Stack Overflow When Changing Scenes v1.2.17

Posted: Mon Aug 23, 2021 5:30 am
by OutbackGames
(UNITY 2020.2.1f1) I'm coming across a very strange issue in which everything acts perfectly in the ways of loading/saving and displaying the data, however.

I am getting a stack overflow on "EnsureRunningOnMainThread" when QM is initializing. The version being used is the most current as I had to fix the issue of Dialogue System Alerts replaying on already completed quests.
(also in the current version, if you put those alerts on the whole quest's success state instead of the success node, they will continue to replay).

This is the print out of the exception.

Code: Select all

StackOverflowException: The requested operation caused a stack overflow.
UnityEngine.Object.EnsureRunningOnMainThread () (at <e414e10bfe5f45729ff122f3359de21b>:0)
UnityEngine.Object.GetInstanceID () (at <e414e10bfe5f45729ff122f3359de21b>:0)
UnityEngine.Object.IsNativeObjectAlive (UnityEngine.Object o) (at <e414e10bfe5f45729ff122f3359de21b>:0)
UnityEngine.Object.CompareBaseObjects (UnityEngine.Object lhs, UnityEngine.Object rhs) (at <e414e10bfe5f45729ff122f3359de21b>:0)
UnityEngine.Object.op_Inequality (UnityEngine.Object x, UnityEngine.Object y) (at <e414e10bfe5f45729ff122f3359de21b>:0)
PixelCrushers.QuestMachine.QuestJournal.get_questJournalUI () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestJournal.cs:38)
PixelCrushers.QuestMachine.QuestJournal.RepaintUIs () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestJournal.cs:214)
PixelCrushers.QuestMachine.QuestJournal.OnMessage (PixelCrushers.MessageArgs messageArgs) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest MonoBehaviours/Quest List/QuestJournal.cs:103)
PixelCrushers.MessageSystem.SendMessageWithTarget (System.Object sender, System.Object target, System.String message, System.String parameter, System.Object[] values) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Message System/MessageSystem.cs:350)
PixelCrushers.MessageSystem.SendMessage (System.Object sender, System.String message, PixelCrushers.StringField parameter, System.Object[] values) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Message System/MessageSystem.cs:450)
PixelCrushers.QuestMachine.QuestMachineMessages.QuestNodeStateChanged (System.Object sender, PixelCrushers.StringField questID, PixelCrushers.StringField questNodeID, PixelCrushers.QuestMachine.QuestNodeState state) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Utility/QuestMachineMessages.cs:165)
PixelCrushers.QuestMachine.QuestNode.SetState (PixelCrushers.QuestMachine.QuestNodeState newState, System.Boolean informListeners) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Node/QuestNode.cs:428)
PixelCrushers.QuestMachine.QuestNode.SetState (PixelCrushers.QuestMachine.QuestNodeState newState, System.Boolean informListeners) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Node/QuestNode.cs:445)
PixelCrushers.QuestMachine.Quest.SetState (PixelCrushers.QuestMachine.QuestState newState, System.Boolean informListeners) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:886)
PixelCrushers.QuestMachine.Quest.Autostart () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:790)
PixelCrushers.QuestMachine.QuestConditionSet.SetTrue () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Condition Set/QuestConditionSet.cs:178)
PixelCrushers.QuestMachine.QuestConditionSet.OnTrueCondition () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Condition Set/QuestConditionSet.cs:173)
PixelCrushers.QuestMachine.QuestCondition.SetTrue () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Subasset/Quest Condition/QuestCondition.cs:63)
PixelCrushers.QuestMachine.QuestStateQuestCondition.StartChecking (System.Action trueAction) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Subasset/Quest Condition/QuestStateQuestCondition.cs:53)
PixelCrushers.QuestMachine.QuestConditionSet.StartChecking (System.Action trueAction) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest Condition Set/QuestConditionSet.cs:128)
PixelCrushers.QuestMachine.Quest.SetStartChecking (System.Boolean enable) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:771)
PixelCrushers.QuestMachine.Quest.SetState (PixelCrushers.QuestMachine.QuestState newState, System.Boolean informListeners) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:865)
PixelCrushers.QuestMachine.Quest.BecomeOfferable () (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:797)
PixelCrushers.QuestMachine.Quest.SetStartChecking (System.Boolean enable) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:778)
PixelCrushers.QuestMachine.Quest.SetState (PixelCrushers.QuestMachine.QuestState newState, System.Boolean informListeners) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:865)
Additional Note: The Following set of lines are repeated continuously down the stack.
"PixelCrushers.QuestMachine.Quest.SetStartChecking (System.Boolean enable) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:778)
PixelCrushers.QuestMachine.Quest.SetState (PixelCrushers.QuestMachine.QuestState newState, System.Boolean informListeners) (at Assets/Plugins/Pixel Crushers/Quest Machine/Scripts/Quest/Quest.cs:865)"



This is what I use to save and load the data from the systems (JIC that is also needed):

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OutbackGames.ARPG.Core;
using PixelCrushers;
using Sirenix.OdinInspector;
namespace OutbackGames.ARPG.Thirdparty
{
    public class PixelCrushersSaveManager : MonoBehaviour
    {
        [SerializeField, ReadOnly, Multiline, BoxGroup("Debug")] string _savedData = "";
        private void Start()
        {
            //LoadSavedData(); //does not work, must call from game manager when it is initializing.
        }

        public void LoadSavedData()
        {
            string prevSavedData = GameStateSaver.LoadKeyFromFile<string>(Constants.PXC_DIAG_QUEST, Constants.questDataFileName);
            _savedData = prevSavedData;
            SaveSystem.ApplySavedGameData(SaveSystem.Deserialize<SavedGameData>(prevSavedData));
        }


        private void OnDisable()
        {
            //SaveData(); //does not work, must call from gamemanager before transition coroutine.
        }

        public void SaveData()
        {
            //Ensure Data Is Collected and objects are notified
            SaveSystem.BeforeSceneChange();
            //SaveSystem.RecordSavedGameData();
            string serializedData = SaveSystem.Serialize(SaveSystem.RecordSavedGameData());
            GameStateSaver.SaveKeyToFile<string>(Constants.PXC_DIAG_QUEST, serializedData, Constants.questDataFileName);
        }
    }

}
Thanks for any help! :D

Re: Stack Overflow When Changing Scenes v1.2.17

Posted: Mon Aug 23, 2021 6:40 am
by OutbackGames
Update:
Looks to be related to operation order. Updated the script execution order in the inspector for my game manager script to run after the save system has initialized itself.

Re: Stack Overflow When Changing Scenes v1.2.17

Posted: Mon Aug 23, 2021 8:40 am
by Tony Li
Hi,

Glad you got to the bottom of it.

Tip: If the issue is that the save data hasn't completely been applied yet, you can hook into the SaveSystem.saveDataApplied event to know when the save system has finished applying saved game data. Side note: You can also use a SaveSystemEvents component or, if you're using a Dialogue System Trigger, you can set it to OnSaveDataApplied.

If the issue is that the Save System isn't initialized in the first place, it initializes in Awake. As a general rule, make sure not to access other components' properties or methods, including the Save System's, in a scene's Awake stage because they might not be initialized yet.

Re: Stack Overflow When Changing Scenes v1.2.17

Posted: Mon Aug 23, 2021 8:52 am
by OutbackGames
Ah that's wonderful to know about the event, I will probably use that to be honest, it will help with me sticking to my patterns.