citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.4k stars 1.99k forks source link

CreateObjectNoOffset on server crashes client if object is changed #2583

Closed DarinBeard closed 4 days ago

DarinBeard commented 3 weeks ago

What happened?

If I create an object using CreateObjectNoOffset on the server side... then the owner on client side alters the object by setting collision to off/on or freezing position it crashes the client. OneSync related? Clonemanager is mentioned in the error. I am not sure what settings changed are causing it but those are the two I've tested and it consistently crashes with this message.

[ 207062] [b3095_DumpServ] 10552/ Process crash captured. Crash dialog content: [ 207062] [b3095_DumpServ] 10552/ GTA5_b3095.exe!sub_1416E43B0 (0x5b) [ 207062] [b3095_DumpServ] 10552/ An error at GTA5_b3095.exe!sub_1416E43B0 (0x5b) caused FiveM to stop working. A crash report is being uploaded to the FiveM developers. [ 207062] [b3095_DumpServ] 10552/ [ 207062] [b3095_DumpServ] 10552/ Legacy crash hash: fish-bulldog-missouri [ 207062] [b3095_DumpServ] 10552/ Stack trace: [ 207062] [b3095_DumpServ] 10552/ GTA5_b3095.exe!sub_1416E43B0 (0x5b) [ 207062] [b3095_DumpServ] 10552/ GTA5_b3095.exe!sub_1411CF2A0 (0x89) [ 207062] [b3095_DumpServ] 10552/ GTA5_b3095.exe!sub_1411C9F10 (0x14c) [ 207062] [b3095_DumpServ] 10552/ GTA5_b3095.exe!sub_1411C8BA4 (0xaaf) [ 207062] [b3095_DumpServ] 10552/ gta-net-five.dll!rage::netObject::Update (0x51) (netObject.h:166) [ 207078] [b3095_DumpServ] 10552/ gta-net-five.dll!sync::CloneManagerLocal::Update (0x1de) (CloneManager.cpp:1911) [ 207078] [b3095_DumpServ] 10552/ gta-net-five.dll!std::invoke (0x4) (type_traits:1576) [ 207078] [b3095_DumpServ] 10552/ [ 213203] [b3095_DumpServ] 10552/ Crash report service returned si-95d10f6b06544260959fdaa1c3d54782

Expected result

It not to crash

Reproduction steps

  1. CreateObjectNoOffset on server
  2. Go to client of owner and change the object's position and that's fine
  3. Change the object's collision and/or whether its position is frozen and the client crashes

Importancy

Crash

Area(s)

FiveM

Specific version(s)

FiveM 8444 fx b7326

Additional information

No response

ahcenezdh commented 3 weeks ago

Can you provide a code example to reproduce the error please?

DarinBeard commented 3 weeks ago

Let me see if I can work up a simple example, the one I have is pretty complicated and long.

DarinBeard commented 3 weeks ago

I have had this be successful without a crash a couple of times but the vast majority of the time it crashes, some times the crash is delayed by a second or two. Very strange. (I don't know why the formatting is freaking out)

SERVER

        private async void SpawnObject_s([FromSource] Player source, string model, Vector3 coords, int objAttachedNet)
        {
            int obj = -1;
            obj = CreateObjectNoOffset((uint)GetHashKey(model), coords.X, coords.Y, coords.Z, true, true, false);
            while (!DoesEntityExist(obj))
            {
                await Delay (0);
            }
            Prop p = new Prop(obj);
            SetEntityDistanceCullingRadius(p.Handle, 100000);
            p.State.Set("spawner", source.Handle, true);
            p.State.Set("spawner_c", false, true);
            source.TriggerEvent("BigDaddy-ObjectSpawner:SpawnObject_c", model, objAttachedNet, coords);
        }

CLIENT

        private async void SpawnObject_c(string model, int objNet, Vector3 coords)
        {
            int obj = -1;
            Prop p = null;
            bool waiting = true;
//if you know a better way to connect the server created object to the client please let me know
            while (waiting)
            {
                await Delay(0);
                p = new Prop(GetClosestObjectOfType(Game.PlayerPed.Position.X, Game.PlayerPed.Position.Y, Game.PlayerPed.Position.Z, 3, (uint)GetHashKey(model), false, false, false));
                if (p != null && p.Exists() && p.State.Get("spawner_c") == false)
                {
                    prop = p.Handle;
                    obj = p.NetworkId;
                    p.State.Set("spawner_c", true, true);
                    waiting = false;
                }

            }

        SetEntityCollision(prop, false, true);
        PlaceObjectOnGroundProperly(prop);

        SetNetworkIdExistsOnAllMachines(obj, true);
        SetNetworkIdCanMigrate(obj, true);
        NetworkSetNetworkIdDynamic(obj, true);

        coords = GetEntityCoords(prop, true);
        x = coords.X;
        y = coords.Y;
        z = coords.Z;

        SetEntityAlpha(prop, 200, 0);
        await Delay(1000);
        SetEntityAlpha(prop, 255, 0);

        SetEntityCollision(prop, true, true);
        FreezeEntityPosition(prop, true);
        }
DarinBeard commented 3 weeks ago

To make sense of that usually I have a bit that allows the client to move the item around and then set it in place. So it just skips the moving around part and sets it in the example above.