crosire Posted March 16, 2013 Share Posted March 16, 2013 (edited) I decided to put something up using the DotNet Scripthook. Well, everything is working quite well, except one issue I keep running into.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: CODE 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) at GTA.Script.TryTick() at GTA.Script.DoTick() at GTA.ScriptThread.OnTick() 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.Cheers,Crosire Edited April 20, 2015 by Crosire Link to comment Share on other sites More sharing options...
crosire Posted March 17, 2013 Author Share Posted March 17, 2013 The error vanished after some changes again and was replaced by a new one. I'm checking all cars with "if (!vehicle.isRequiredforMission) { .. }" before I continue in my code. That works fine most of the time, but after about 2 minutes the script crashes again with the same exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at NativeInvoke.Invoke<bool,int>(SByte* name, Int32 p1) at Scripting.?A0x8c04474b.IsCarAMissionCar(Int32 ) at GTA.Vehicle.get_isRequiredForMission() at --.--.Tick--(Object sender, EventArgs e) at System.EventHandler.Invoke(Object sender, EventArgs e) at GTA.Script.TryTick() at GTA.Script.DoTick() at GTA.ScriptThread.OnTick() Link to comment Share on other sites More sharing options...
pedro2555 Posted March 17, 2013 Share Posted March 17, 2013 Do you check if the vehicle is still loaded ? You should get a no instance exception in that case but, oh well, who knows. And try out the native functions for that to see if there is any difference. There is a SET_ENGINE_HEALTH, there is no documentation for it, but from my experience it should have 2 parameters, SET_ENGINE_HEALTH(Vehicle handle, Single health) Also I have found it easier to simply have a second script doing background work, instead of a different thread on the same script. It is a bit non-sense but, for me it has been more easier to deal with. And since both scripts run from the same assembly that is super easy to transfer data between them. Just use internal static members for that, and make sure to clear them after reading, I think the Garbage Collector will not do that for you, in this case, but you can always check that. Link to comment Share on other sites More sharing options...
crosire Posted March 18, 2013 Author Share Posted March 18, 2013 I'm already doing that by now. Having one script/thread (the scripthook handles each script in a different thread) cycling through peds and one through vehicles. So if one crashes, the other one still runs. I will check if the errors do go away if I use native functions instead of the ones the .net/cpp scripthook provide. Thanks for the suggestion! Link to comment Share on other sites More sharing options...
crosire Posted March 18, 2013 Author Share Posted March 18, 2013 I fixed the last error by using the native "IS_CAR_A_MISSION_CAR" now. There are still some random access violation exceptions showing up, but they don't crash the script anymore, so one step in the right direction. Thank you again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now