immersivecognition / unity-experiment-framework

UXF - Framework for creating human behaviour experiments in Unity
https://immersivecognition.github.io/unity-experiment-framework/
MIT License
223 stars 44 forks source link

InvalidOperationException: Cant add action to FileIOManager, is currently quitting #50

Closed thefirstfloor closed 4 years ago

thefirstfloor commented 4 years ago

UXF 2.05 Unity 2020.1.12f1 Android project but running in Link PC mode in editor Data handling: File saver enabled

Three active Position trackers in scene. Error happens when calling Session.instance.End();

Console: _InvalidOperationException: Cant add action to FileIOManager, is currently quitting. Action: UXF.FileSaver+<>c__DisplayClass12_0.b_0 UXF.FileSaver.ManageInWorker (System.Action action) (at Assets/UXF/Scripts/DataHandling/FileSaver.cs:82) UXF.FileSaver.HandleDataTable (UXF.UXFDataTable table, System.String experiment, System.String ppid, System.Int32 sessionNum, System.String dataName, UXF.UXFDataType dataType, System.Int32 optionalTrialNum) (at Assets/UXF/Scripts/DataHandling/FileSaver.cs:148) UXF.Session.SaveDataTable (UXF.UXFDataTable table, System.String dataName, UXF.UXFDataType dataType) (at Assets/UXF/Scripts/Session.cs:538) UXF.Session.SaveResults () (at Assets/UXF/Scripts/Session.cs:692) UXF.Session.End () (at Assets/UXF/Scripts/Session.cs:620)

jackbrookes commented 4 years ago

I think maybe what is happening is Session.instance.End(); is being called multiple times, so it is trying to save results whilst it is already saving. I'll see if I can replicate and can deploy a check for this that throws a more helpful error.

jackbrookes commented 4 years ago

Cannot replicate this even when End is called multiple times. Are there no other errors that occur before this?

thefirstfloor commented 4 years ago

Nope. ... Queuing save of file: C:\Users\Jeroen\Documents\XXX\Demo\DemoID\S000\trackers\righthand_controller_movement_T002.csv Joining File Saver Thread Managing action (few times) Finished worker thread Message before the error are: Ended session. Queuing save of file: C:\Users\Jeroen\Documents\MPI SNT\Demo\DemoID\S000\trial_results.csv

Short version of situation: I'm doing Session.instance.BeginNextTrialSafe(); at the end of my trial (user button press) but it does not end the session automatically ('EndAfterLastTrial' checkbox is set to true on the session script in the inspector.) So I manually also call 'Session.instance.end' when my state machine recognises that the system stays in a 'trial ended' state. I only have 1 block with 2 trials at the moment. Any specific info I can post to help further, let me know.
jackbrookes commented 4 years ago

End After Last Trial should definitely work when calling trial.End() (starting the next trial will not automatically end the current one).

I am puzzled as to how it allows Queuing save of file: C:\Users\Jeroen\Documents\MPI SNT\Demo\DemoID\S000\trial_results.csv when the session has already ended.

You can see here, the results get saved BEFORE the session ends.

https://github.com/immersivecognition/unity-experiment-framework/blob/ac14a43d1ea1a81e62e6017d16fab743ed8669ff/Assets/UXF/Scripts/Session.cs#L619-L657

I have not tested with Android, do you know if you switch platform to Windows this error goes away? Any other info you have would be useful. I assume the examples run OK?

jackbrookes commented 4 years ago

If you are willing to host your project on github or elsewhere (perhaps privately if necessary) and invite me I can take a look at the code.

thefirstfloor commented 4 years ago

I am not able to share it online at this point I'm afraid, but: After analysing the flow of the method calls and seeing your remark about trial.end(), I tried to set up the flow a bit different.

My assumption/logic was that BeginNextTrialSafe() or even BeginNextTrial(), will end the current one running, it also shows in the inspector that the system indeed goes to the next trial in the block. So that is a bit misleading.

Instead of calling BeginNextTrialSafe() after my statemachine knows it's the end of the trial, now it does Session.instance.CurrentTrial.End(); I hooked up a method to the UXF OnTrialEnd event that calls the BeginNextTrialSafe(). Also the automatic ending of the session works fine now.

Thanks for diving into it.

jackbrookes commented 4 years ago

Indeed that is misleading, I will try to implement something to address this.