Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Happy Holidays from the GTANet team!

AccessViolation at Scripting.SetCarEngineOn


crosire
 Share

Recommended Posts

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 by Crosire
Link to comment
Share on other sites

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.