Using ES3File in thread causes expection
Posted: Mon Jun 03, 2019 8:22 pm
Hello, I'm trying to create a new ES3File in a thread, I'm pointing to a File that has a single entry of a string so the data is thread safe but I'm getting the following error:
The stacktrace:
I can only assume ES3File tries to update the editor gui for some reason ?
The Save method looks like this:
The load is like this
Code: Select all
GetAll can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
Code: Select all
at (wrapper managed-to-native) UnityEditor.PackageManager.PackageInfo.GetAll()
at UnityEditor.PackageManagerUtilityInternal.GetAllVisiblePackages (System.Boolean skipHiddenPackages) [0x0000e] in C:\buildslave\unity\build\Editor\Mono\PackageManagerUtilityInternal.cs:19
at UnityEditor.AssetDatabase+<FindEverywhere>c__Iterator2`1[T].MoveNext () [0x0008f] in C:\buildslave\unity\build\Editor\Mono\AssetDatabase\AssetDatabaseSearching.cs:109
at UnityEditor.AssetDatabase+<FindAllAssets>c__Iterator0.MoveNext () [0x00063] in C:\buildslave\unity\build\Editor\Mono\AssetDatabase\AssetDatabaseSearching.cs:37
at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].ToArray () [0x00030] in <b7efe7e6e548497fac3c4a6049a0a4b6>:0
at System.Linq.Enumerable.ToArray[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0001f] in <b7efe7e6e548497fac3c4a6049a0a4b6>:0
at UnityEditor.AssetDatabase.FindAssets (UnityEditor.SearchFilter searchFilter) [0x00029] in C:\buildslave\unity\build\Editor\Mono\AssetDatabase\AssetDatabaseSearching.cs:31
at UnityEditor.AssetDatabase.FindAssets (System.String filter, System.String[] searchInFolders) [0x00038] in C:\buildslave\unity\build\Editor\Mono\AssetDatabase\AssetDatabaseSearching.cs:26
at UnityEditor.AssetDatabase.FindAssets (System.String filter) [0x00003] in C:\buildslave\unity\build\Editor\Mono\AssetDatabase\AssetDatabaseSearching.cs:13
at ES3Settings.LoadDefaults () [0x00001] in G:\devl\ecs\Redrook\Assets\Plugins\Easy Save 3\Scripts\Settings\ES3Settings.cs:151
at ES3Settings.ApplyDefaults () [0x0000d] in G:\devl\ecs\Redrook\Assets\Plugins\Easy Save 3\Scripts\Settings\ES3Settings.cs:136
at ES3Settings..ctor () [0x0001a] in G:\devl\ecs\Redrook\Assets\Plugins\Easy Save 3\Scripts\Settings\ES3Settings.cs:74
at ES3Settings..ctor (System.String path) [0x00000] in G:\devl\ecs\Redrook\Assets\Plugins\Easy Save 3\Scripts\Settings\ES3Settings.cs:79
at ES3File..ctor (System.String filePath) [0x00000] in G:\devl\ecs\Redrook\Assets\Plugins\Easy Save 3\Scripts\ES3File.cs:21
at GridSaver.Loader+<>c.<LoadDataAsync>b__11_0 () [0x00001] in G:\devl\ecs\Redrook\Assets\Scripts\GridSaver\Loader.cs:47
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <23c160f925be47d7a4fd083a3a62c920>:0
at System.Threading.Tasks.Task.Execute () [0x00010] in <23c160f925be47d7a4fd083a3a62c920>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <23c160f925be47d7a4fd083a3a62c920>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <23c160f925be47d7a4fd083a3a62c920>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <23c160f925be47d7a4fd083a3a62c920>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <23c160f925be47d7a4fd083a3a62c920>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <23c160f925be47d7a4fd083a3a62c920>:0
at GridSaver.Loader+<LoadDataAsync>d__11.MoveNext () [0x00042] in G:\devl\ecs\Redrook\Assets\Scripts\GridSaver\Loader.cs:45
The Save method looks like this:
Code: Select all
var es3File = new ES3File("david");
es3File.Save<string>("key1", "testString");
es3File.Sync();
Code: Select all
private async Task LoadDataAsync(string sceneName, string[] tileMapsNames)
{
try
{
f = await Task.Run(() =>
{
return new ES3File($"david");
});
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}