CWolfs / MissionControl

A HBS BattleTech mod that provides a framework for runtime modifications of the contracts and encounters.
GNU General Public License v3.0
21 stars 13 forks source link

Custom Contracts: MDD SQL Error #306

Closed CWolfs closed 2 years ago

CWolfs commented 4 years ago

Mission Control has to manually add EncounterLayer to the MDD since ModTek, nor the HBS loader handles that.

I need to improve it as it can sometimes cause a SQL error on BT boot as a race condition or some kind of clash.

Investigate and fix.

CWolfs commented 4 years ago
Uploading Crash Report
Unity [ERROR] SqliteException: SQLite error
not an error

(Filename: C:\buildslave\unity\build\Runtime/Export/Debug.bindings.h Line: 45)

SqliteException: SQLite error
not an error
  at Mono.Data.Sqlite.SQLite3.Reset (Mono.Data.Sqlite.SqliteStatement stmt) [0x00096] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at Mono.Data.Sqlite.SQLite3.Step (Mono.Data.Sqlite.SqliteStatement stmt) [0x00046] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at Mono.Data.Sqlite.SqliteDataReader.NextResult () [0x00129] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteDataReader.NextResult()
  at Mono.Data.Sqlite.SqliteDataReader..ctor (Mono.Data.Sqlite.SqliteCommand cmd, System.Data.CommandBehavior behave) [0x00051] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteDataReader..ctor(Mono.Data.Sqlite.SqliteCommand,System.Data.CommandBehavior)
  at Mono.Data.Sqlite.SqliteCommand.ExecuteReader (System.Data.CommandBehavior behavior) [0x00006] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at Mono.Data.Sqlite.SqliteCommand.ExecuteNonQuery () [0x00000] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0
at BattleTech.Data.MetadataDatabase.DetachMDDFromInMemoryDB () [0x00017] in <4184af8dbeb44635831353f4d349631c>:0 
  at BattleTech.Data.MetadataDatabase.WriteInMemoryDBToDisk (System.String filePath) [0x000fa] in <4184af8dbeb44635831353f4d349631c>:0 
  at MissionControl.DataManager.LoadCustomContractTypes () [0x00072] in <f15ecd11837d4fde8e934f3fce3abebb>:0 
  at MissionControl.DataManager.LoadDeferredDefs () [0x00016] in <f15ecd11837d4fde8e934f3fce3abebb>:0 
  at MissionControl.Patches.MainMenuInitPatch.Postfix (BattleTech.UI.MainMenu __instance) [0x00071] in <f15ecd11837d4fde8e934f3fce3abebb>:0 
  at (wrapper dynamic-method) BattleTech.UI.MainMenu.Init_Patch2(object)
  at BattleTech.UI.UIManager.AddModule (BattleTech.UI.UIModule module, BattleTech.UI.UIManager+UINode node, System.Int32 depth, System.Boolean resort) [0x0008f] in <4184af8dbeb44635831353f4d349631c>:0 
  at BattleTech.UI.UIManager.GetOrCreateAtNode (System.Type moduleType, System.String prefabName, BattleTech.UI.UIManager+UINode node, System.Boolean tryGet, System.Boolean resort) [0x00067] in <4184af8dbeb44635831353f4d349631c>:0 
  at BattleTech.UI.UIManager.CreateUIModule (System.Type moduleType, System.String prefabOverride, System.Boolean resort) [0x0000a] in <4184af8dbeb44635831353f4d349631c>:0 
  at BattleTech.UI.ModuleAutoLauncher.Launch () [0x00056] in <4184af8dbeb44635831353f4d349631c>:0 
  at BattleTech.UI.ModuleAutoLauncher+<Start>d__7.MoveNext () [0x00046] in <4184af8dbeb44635831353f4d349631c>:0 
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00027] in <9a6ceb7f013a4a599806f492fc789483>:0 
CWolfs commented 4 years ago

This issue mainly happened for users on HDD (non-SSD drives).

I've delayed the writing of the custom contract types to the MDD for a second (configurable in the settings.json with:

 ContractTypeLoaderWait: 1000, // milliseconds

I originally tested this with a user with 2 seconds wait but I feel that's excessive. I've made it configurable to ensure if reducing it causes problems then a user can edit it on my instructions - until I increase the default on a next patch.

I've also threaded this as I didn't want to introduce any pauses on the Unity main thread.

CWolfs commented 4 years ago

This issue can happen still in the new thread but at least it doesn't block the game anymore. I'll see what I can do to sort this out again.

I've seen a report of MDD_DB is locked which is different to the previous error.

SqliteException: SQLite error
database MDD_DB is locked
  at Mono.Data.Sqlite.SQLite3.Reset (Mono.Data.Sqlite.SqliteStatement stmt) [0x00096] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at Mono.Data.Sqlite.SQLite3.Step (Mono.Data.Sqlite.SqliteStatement stmt) [0x00046] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at Mono.Data.Sqlite.SqliteDataReader.NextResult () [0x00129] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteDataReader.NextResult()
  at Mono.Data.Sqlite.SqliteDataReader..ctor (Mono.Data.Sqlite.SqliteCommand cmd, System.Data.CommandBehavior behave) [0x00051] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at (wrapper remoting-invoke-with-check) Mono.Data.Sqlite.SqliteDataReader..ctor(Mono.Data.Sqlite.SqliteCommand,System.Data.CommandBehavior)
  at Mono.Data.Sqlite.SqliteCommand.ExecuteReader (System.Data.CommandBehavior behavior) [0x00006] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at Mono.Data.Sqlite.SqliteCommand.ExecuteNonQuery () [0x00000] in <99f7d8f9a65b4d91ae5b1d55c424866f>:0 
  at BattleTech.Data.MetadataDatabase.DetachMDDFromInMemoryDB () [0x00017] in <4184af8dbeb44635831353f4d349631c>:0 
  at BattleTech.Data.MetadataDatabase.WriteInMemoryDBToDisk (System.String filePath) [0x000fa] in <4184af8dbeb44635831353f4d349631c>:0 
  at MissionControl.DataManager.WriteMDDToDisk () [0x00067] in <298242ac43a1436ba66695f4343f6a75>:0 
  at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
  at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
  at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
  at System.Threading.ThreadHelper.ThreadStart () [0x00008] in <d7ac571ca2d04b2f981d0d886fa067cf>:0 
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.UnhandledExceptionHandler:<RegisterUECatcher>m__0(Object, UnhandledExceptionEventArgs)
CWolfs commented 2 years ago

Since I upgraded Modtek v2 to load EncounterLayers this no longer happens in Modtek v2.