ClonkAndre / ScriptHookDotNet-for-IVSDKDotNet

GTA IV ScriptHookDotNet from HazardX with a IV-SDK .NET translation layer on-top to make mods created with ScriptHookDotNet work with IV-SDK .NET!
MIT License
5 stars 0 forks source link

While loop issue (Weapon Animation Tweaks and Functions script) #21

Closed LotsofEds closed 1 month ago

LotsofEds commented 2 months ago

https://www.gtainside.com/en/gta4/mods/200374-weapon-animation-tweaks-and-functions/

I know it's weird to report an issue of my own mod but while working on my WeapFuncs mod, I stumbled into a weird compatibility issue. I was using a while loop to get the players current ammo in the clip during a certain time of an animation. Here is a snippet of the code:             GTA.Native.Function.Call("GET_CHAR_ANIM_CURRENT_TIME", Player.Character, "cover_r_low_corner", "pistol_blindfire", AnimPointer);             while (AnimPointer > 0.06&&AnimPointer < 0.1)             {                 Boolet = Player.Character.Weapons.Current.AmmoInClip;             }

This causes the game to freeze without any sort of error message or crash log being created. However when I changed it to an if statement, the script works just fine.

Tested on CE downgraded to 1.0.7.0 using version 1.5 of IVSDK.net with version 1.7.2.2 of ScripthookDotNet found in the bin folder by default.

ClonkAndre commented 2 months ago

It's because the while loop is blocking the current thread and this is causing the freeze. If you are able to avoid the while loop and use an if statement, you should prefer that. The thing is every IV-SDK .NET script is running on the same thread so this is the reason why it hangs. I like to avoid using while loops just because of that reason 🥴.

LotsofEds commented 2 months ago

Ahh so while loops are just a no-go then, gotcha. That's unfortunate, but thank you anyways.