SayagoHren 4 Posted June 14, 2020 Share Posted June 14, 2020 (edited) Hello everybody, I have encountered a new problem why trying to create my first mod (more agressive wanted level). When I clear tasks for created peds and marking them as no longer needed (when player has wanted level 0) the game just crashes. Strange thing is that if I do not have much peds this function works properly. I also use in mod custom cars but I think it is not reason because this function does not affect directly car spawning, but maybe i am mistaking. Hope you can help me. Was searching for hours information about such kind of problem but did not found. Problem aso is not linked with system file corruption e.t.c because i made full windows reinstall with latest drivers, microsoft visual redist c++ and other simular things. The system is clean. Application error in windows event viewer Spoiler Bad application name: GTA5.exe, version: 1.0.1868.1, timestamp: 0x5e7d1d62 Failed module name: KERNELBASE.dll, version: 10.0.19041.292, timestamp: 0x84cd251b Exception Code: 0xe0434352 Error offset: 0x0000000000023e49 Process ID: 0x3454 Application start-up time: 0x01d6421f2f3e5e07 Bad application path: C: \ Program Files (x86) \ Steam \ steamapps \ common \ Grand Theft Auto V \ GTA5.exe Failed module path: C: \ Windows \ System32 \ KERNELBASE.dll Report ID: b8a0baf3-449a-40cc-8f81-70582a17d297 .NET runtime error in windows event viewer Spoiler Application: GTA5.exe Platform Version: v4.0.30319 Description. The process was completed due to an unhandled exception. Exception Details: System.AccessViolationException at SHVDN.NativeFunc.NativeCall () at SHVDN.NativeFunc.NativeTask.Run () at SHVDN.ScriptDomain.DoTick () at SHVDN.ScriptDomain.DoTick () in <Module>.? A0xc1aa4bd5.ScriptHookVDotnet_ManagedTick () Edited June 14, 2020 by SayagoHren Link to post Share on other sites More sharing options...
Jitnaught 424 Posted June 14, 2020 Share Posted June 14, 2020 Are you able to post a code example? Or can you give a more descriptive example of what you're doing so we can test ourselves? e.g. "spawn 25 peds, then clear tasks and mark as not needed for all of them." Link to post Share on other sites More sharing options...
SayagoHren 4 Posted June 14, 2020 Author Share Posted June 14, 2020 (edited) Thank you for the answer, sorry thought that information mentioned in my post was enough. In my mod I spawn random (random model) extra police cars, when wanted level is zero I clean tasks for peds in cars and mark all peds as no longer needed so they drive away and free memory. All these things happen in OnTick Event with interval 5 seconds. Under spoiler added spawn code. if (Function.Call<int>(Hash.GET_PLAYER_WANTED_LEVEL, Game.Player) == 0) { ClearAllLawForcesTasks(); // this code in OnTick event } private void ClearAllLawForcesTasks() { CleanPedTasks(ref peds_3_1, 16); CleanPedTasks(ref peds_6_1, 16); CleanPedTasks(ref peds_6_2, 16); CleanPedTasks(ref peds_6_3, 16); CleanPedTasks(ref peds_6_4, 16); CleanPedTasks(ref peds_6_5, 16); } private void CleanPedTasks(ref Ped[] peds_to_clean_task, int size_of_peds_array) { for (int i = 0; i < size_of_peds_array; i++) { if ( Function.Call<bool>(Hash.DOES_ENTITY_EXIST, peds_to_clean_task[i]) & !Function.Call<bool>(Hash.IS_ENTITY_DEAD, peds_to_clean_task[i])) { peds_to_clean_task[i].Task.ClearAll(); peds_to_clean_task[i].MarkAsNoLongerNeeded(); } } } Spoiler SpawnAnyCar("Rhino", ref v_6_1, ref peds_6_1, 5, 150.0F);// on tick event private void SpawnAnyCar(Model VehicleModel, ref Vehicle AnyCar, ref Ped[] PedsAnyCar, int peds_type, float SpawnDistance) { car_spawn_position = GenerateSpawnPos(Game.Player.Character.Position + Game.Player.Character.ForwardVector * SpawnDistance, Nodetype.Road, false); AnyCar = World.CreateVehicle(VehicleModel, car_spawn_position); AnyCar.PlaceOnGround(); if (Game.Player.Character.IsInVehicle()) { AnyCar.Heading = Game.Player.Character.CurrentVehicle.Heading - 180; } else { AnyCar.Heading = Game.Player.Character.Heading - 180; } AnyCar.EngineRunning = true; AnyCar.SirenActive = true; PassengerCapacity = Function.Call<int>(Hash.GET_VEHICLE_MAX_NUMBER_OF_PASSENGERS, AnyCar); for (int i = -1; i < PassengerCapacity; i++) { switch (peds_type) { case 0: if (i > -1){ped_index = ped_index +1;}//synchronising ped index with cycle counter pedselect_cops(); PedsAnyCar[ped_index] = AnyCar.CreatePedOnSeat((VehicleSeat)i, pedmodel_cops); break; case 1: if (i > -1){ped_index = ped_index +1;}//synchronising ped index with cycle counter PedsAnyCar[ped_index] = AnyCar.CreatePedOnSeat((VehicleSeat)i, "s_m_y_swat_01"); break; case 2: if (i > -1){ped_index = ped_index +1;}//synchronising ped index with cycle counter pedselect_fbi(); PedsAnyCar[ped_index] = AnyCar.CreatePedOnSeat((VehicleSeat)i, pedmodel_fbi); break; case 3: if (i > -1){ped_index = ped_index +1;}//synchronising ped index with cycle counter pedselect_medic(); PedsAnyCar[ped_index] = AnyCar.CreatePedOnSeat((VehicleSeat)i, pedmodel_medic); break; case 4: if (i > -1){ped_index = ped_index +1;}//synchronising ped index with cycle counter pedselect_detective(); PedsAnyCar[ped_index] = AnyCar.CreatePedOnSeat((VehicleSeat)i, pedmodel_detective); break; case 5: if (i > -1){ped_index = ped_index +1;}//synchronising ped index with cycle counter pedselect_army(); PedsAnyCar[ped_index] = AnyCar.CreatePedOnSeat((VehicleSeat)i, pedmodel_army); break; default: if (i > -1){ped_index = ped_index +1;}//synchronising ped index with cycle counter PedsAnyCar[ped_index] = AnyCar.CreatePedOnSeat((VehicleSeat)i, "s_m_y_swat_01"); break; } weapselect(); PedsAnyCar[ped_index].Weapons.Give(weaphash, 999, true, true); Function.Call(Hash.SET_PED_AS_COP, PedsAnyCar[ped_index], true); } if (!Game.Player.Character.IsInVehicle()) { PedsAnyCar[0].Task.DriveTo(AnyCar, Game.Player.Character.Position, 10, 50); } else { PedsAnyCar[0].Task.VehicleChase(Game.Player.Character); } PedsAnyCar[0].AlwaysKeepTask = true; ped_index = 0; }// End of SpawnAnyCar method Edited June 14, 2020 by SayagoHren Link to post Share on other sites More sharing options...
ikt 288 Posted June 25, 2020 Share Posted June 25, 2020 Some other person on 5mods reported a similar issue. Since he only mentioned MarkAsNoLongerNeeded, I'd try just calling the native yourself. With the limited amount of code, I can't spot anything wrong, but clearly there's a dangling pointer/reference/handle somewhere that causes these crashes. Link to post Share on other sites More sharing options...
SayagoHren 4 Posted June 27, 2020 Author Share Posted June 27, 2020 If I call directly this native it causes the crash with the same error even when the amount of peds is not big Code of function: Spoiler private void CleanPedTasks(ref Ped[] peds_to_clean_task, int size_of_peds_array) { for (int i = 0; i < size_of_peds_array; i++) { if ( Function.Call<bool>(Hash.DOES_ENTITY_EXIST, peds_to_clean_task[i]) & !Function.Call<bool>(Hash.IS_ENTITY_DEAD, peds_to_clean_task[i])) { //peds_to_clean_task[i].MarkAsNoLongerNeeded(); Function.Call(Hash.SET_ENTITY_AS_NO_LONGER_NEEDED, peds_to_clean_task[i]); } } } Error in windows events viewer: Spoiler Application: GTA5.exe Platform Version: v4.0.30319 Description. The process was completed due to an unhandled exception. Exception Details: System.AccessViolationException at SHVDN.NativeFunc.NativeCall () at SHVDN.NativeFunc.NativeTask.Run () at SHVDN.ScriptDomain.DoTick () at SHVDN.ScriptDomain.DoTick () in <Module>.? A0xc1aa4bd5.ScriptHookVDotnet_ManagedTick () Link to post Share on other sites More sharing options...
ikt 288 Posted June 27, 2020 Share Posted June 27, 2020 Odd, could be the array accessor going wrong. Try using a List<Ped> instead? Link to post Share on other sites More sharing options...
SayagoHren 4 Posted June 27, 2020 Author Share Posted June 27, 2020 (edited) Checked it out, using array is not the problem. Test code: Spoiler Ped test_ped_1; Ped test_ped_2; Ped test_ped_3; Ped test_ped_4; private void TestCleanPedTasks(ref Ped peds_to_clean_task) { { if ( Function.Call<bool>(Hash.DOES_ENTITY_EXIST, peds_to_clean_task) & !Function.Call<bool>(Hash.IS_ENTITY_DEAD, peds_to_clean_task)) { //peds_to_clean_task[i].MarkAsNoLongerNeeded(); Function.Call(Hash.SET_ENTITY_AS_NO_LONGER_NEEDED, peds_to_clean_task); } } } private void onKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.H) { Vector3 peds_spawn_position = World.GetNextPositionOnSidewalk(Game.Player.Character.Position + Game.Player.Character.ForwardVector * 5); test_ped_1 = World.CreateRandomPed(peds_spawn_position); test_ped_2 = World.CreateRandomPed(peds_spawn_position); test_ped_3 = World.CreateRandomPed(peds_spawn_position); test_ped_4 = World.CreateRandomPed(peds_spawn_position); } if (e.KeyCode == Keys.J) { TestCleanPedTasks(ref test_ped_1); TestCleanPedTasks(ref test_ped_2); TestCleanPedTasks(ref test_ped_3); TestCleanPedTasks(ref test_ped_4); } }// end of keydown . Game crashes with same error code "system access violation" after trying to press "J". Edited June 27, 2020 by SayagoHren Link to post Share on other sites More sharing options...
PietroKaro 0 Posted July 21, 2020 Share Posted July 21, 2020 I did two more tests about this problem: TEST 1: - More than 45 police riots spawned in game; - For each riot, there was only one ped(COP01 SMY) as driver; - Mark all police riot driver as no longer needed. Result: everything ok. TEST 2: - Around 45 police riots spawned in game; - For each riot, there were two peds (COP01 SMY); - Mark all police riot ped as no longer needed. Result: game crash. It seems the problem depend on how many peds are spawned in vehicles and how many vehicles are spawned in game. For example, if you spawn five vehicles with seven seats each and then occupy all those seats with peds, when you call MarkAsNoLongerNeeded() for each ped, everything always will be fine because 7 peds * 5 vehicles = 35 (the game will handle it correctly). If you make the same test with more than 38 - 42 peds, the game will crash because it seems RAGE Engine fails to mark all peds as no longer needed. I don't know if the problem is related to the max spawnable entities that set to gameconfig files. Link to post Share on other sites More sharing options...
briancatmaster 0 Posted Tuesday at 12:20 AM Share Posted Tuesday at 12:20 AM (edited) Did you figure out a fix to this problem, I have a similar issue with the exact same error code and I also using mark as no longer needed on cops. ?A0xc1aa4bd5.ScriptHookVDotnet_ManagedTick() Edited Tuesday at 12:20 AM by briancatmaster Link to post Share on other sites More sharing options...