One of my scripting threads loops through all vehicles around the player and eventually sets the engine health to "0f" for some of them. That normally works totally fine and there isn't really anything in the code that might fail there. But since several days I keep getting a "AccessViolationException", which then obviously crashes the script. Last time that error stayed for two days and went away after several attemps of changing code, clearing settings, etc. Everything was working for some time now, but suddenly, without any change it the code it came back.
Full stack trace:
|System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.|
at NativeInvoke.Invoke<int,int,bool,bool>(SByte* name, Int32 p1, Boolean p2, Boolean p3)
at Scripting.?A0x8c04474b.SetCarEngineOn(Int32 , Boolean , Boolean )
at GTA.Vehicle.set_EngineHealth(Single value)
at --.--.Tick_Main(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
As you can see it tries to enable the car engine somewhy (while I'm only changing the engine health). I asume this is the way, the DotNet script hook changes the health there after looking into its managed source.
I'm somewhere lost here and I hope somebody with experience can help me here.