Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
NModds

Memory Leaks! [C#]

Recommended Posts

NModds

Hi all,

 

I think my code is causing memory leaks and crashing GTAV with repeated use, sometimes with game memory error and others without. I have read online that one of the main causes to programs crashing is memory leaks and people had many suggestions for solving such an event. One of them was a memory profiler. I looked online for a c#-dll memory profiler and really couldn't find anything that worked for a class library. Is there a way to detect memory leaks for GTAV scripts?

Share this post


Link to post
Share on other sites
Bob_74

I don't know about C# memory leak, but did you check you hook log file to see what happened exactly?

ScriptHookVDotNet and RagePluginHook generates log file on crash with the detail of the exception that has been raised.

Share this post


Link to post
Share on other sites
NModds

I don't know about C# memory leak, but did you check you hook log file to see what happened exactly?

ScriptHookVDotNet and RagePluginHook generates log file on crash with the detail of the exception that has been raised.

 

When I first started getting the crash, I did check and scripthookdotnet log, but it didn't write anything. So I assumed that scripthookvdotnet didn't have time to find the error because the game crashed prematurely. But just to make sure I will try and reproduce the error and see what scripthookdotnet's log states.

Share this post


Link to post
Share on other sites
Bob_74

Be careful, if you restart ScriptHookVDotNet (restarting the game or using the "Inser" key), it will reset the log file. You need to check it as soon as the mod has crashed or right after exiting the game ;)

Share this post


Link to post
Share on other sites
NModds

Be careful, if you restart ScriptHookVDotNet (restarting the game or using the "Inser" key), it will reset the log file. You need to check it as soon as the mod has crashed or right after exiting the game ;)

I recreated the error, sadly Scripthookvdotnet didn't catch any errors nor Scripthook.log. I just get a message saying gta5 crashed, gives me an option to debug. when I click on debug, it states that an unhandled Microsoft .net framework exception was raised in gta5.exe. I notice that when I want to do a great deal of manipulation on different # of lists the game crashes, which is why I thought something is adding up and compounding to affect memory but I'm not sure with my current understanding of memory handling in gta5. I was also thinking that it could be caused by CPU processing time. Since I am trying not to deplete fps I request scripthookvdotnet to give me a list of peds/objects/vehicles within maybe a 1-10 millisec window and immediately try to manipulate them. But I know even less about CPU, so I'm just aiming wildly trying to find the answer.

Edited by nm710

Share this post


Link to post
Share on other sites
Bob_74

If the game is crashing, it can comes from a ScriptHookV (asi) script that crash or from your ScriptHookVDotNet script that runs through an infinite loop (or a loop that is too long and that doesn't have Script.Yield() or .Wait()).

I suggest you write a line into a log file at the beginning and the end of your heavy loop to see if the problem really comes from here.

Also, if you store Peds, Vehicles, etc, try to loop through your list and remove the elements if Entity.Exists() == false

I don't think it is a memory leak problem linked to C# but you should be able to check the memory usage if you open windows task manager (performance tab) and put it on a second screen or on the same screen with the game in windowed mode.

Edited by Bob_74

Share this post


Link to post
Share on other sites
NModds

If the game is crashing, it can comes from a ScriptHookV (asi) script that crash or from your ScriptHookVDotNet script that runs through an infinite loop (or a loop that is too long and that doesn't have Script.Yield() or .Wait()).

 

I suggest you write a line into a log file at the beginning and the end of your heavy loop to see if the problem really comes from here.

 

Also, if you store Peds, Vehicles, etc, try to loop through you list and remove the elements if Entity.Exists() == false

 

I don't think it is a memory leak problem linked to C# but you should be able to check the memory usage if you open windows task manager (performance tab) and put it on a second screen or on the same screen with the game in windowed mode.

Ok, thanks. I will try your suggestions and report back.

Share this post


Link to post
Share on other sites
NModds

I manged to find one case that always crashed the game. A blachole kind of power. A list of props in which I pull them to a vector position and delete the prop when the get close to the vector3 then remove them from the list. This crashed the game after 4+ use. Removing props that satisfy !Prop.Exists() helped reduce the time of crash, but interestingly the wait() function I think made it crash faster, after 2-3 attempts of using the power. After several iteration of changing the code, and several crashes later I got rid of the Prop.delete() function from my script and instead changed it to Prop.Position = Vector3.Zero and then remove it from the list, letting gtav handle the deleting of the props. I believe this has solved the problem since I haven't got any crashes despite the fact that I increased the radius of list collection. There are still crashes that occur but those are random and they take place after an hour - 2 hour use. Thanks again :).

 

 

 

 

Share this post


Link to post
Share on other sites
Bob_74

That's a bit odd, the game should handle Prop.delete() without any issue.

 

If you end up teleporting the props instead of deleting them, do you remove the persistence and tag the prop as no longer needed?

Otherwise the game may not delete the props by itself.

Entity.IsPersistent = false;Entity.MarkAsNoLongerNeeded();

Share this post


Link to post
Share on other sites
NModds

I didn't add it because I thought we add MarkAsNoLongerNeeded() if we created the Entity, and not when it's already present in the game and that IsPersistent by default is false. But since there is no harm in adding it, I will add it. I also found it odd that Prop.delete() caused a consistent crash, since I use that function for objects that I created.

Edited by nm710

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 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.