Jump to content

New GameFiber crashes LSPDFR


AlexKardone

Recommended Posts

Hello! Can you help me with my problem? I try to create new callout. In this script the suspect will approach to the undercover cop, then they will talk for 3 sec, and then the chase wil start. But, when I invoke GameFiber.Sleep(), the Plugin crashes. What is wrong? Thanks.

public override void Process()
        {
            base.Process();

            GameFiber.StartNew(delegate
            {
                if (!PursuitCreated && Cop.DistanceTo(Suspect.Position) < 2f)
                {
                    GameFiber.Sleep(3000);
                    PursuitCreated = true;

                    Pursuit = Functions.CreatePursuit();
                    Functions.AddPedToPursuit(Pursuit, Suspect);
                    Functions.AddCopToPursuit(Pursuit, Cop);
                    Functions.SetPursuitIsActiveForPlayer(Pursuit, true);

                }
                if (PursuitCreated && !Functions.IsPursuitStillRunning(Pursuit))
                {
                    Game.LogTrivial("End executed!");
                    End();
                }
            }, "newFiber");
        }

 

Edited by AlexKardone
Link to comment
Share on other sites

I've understood what happened. After creating a new Fiber the script is executing the Process() method and check the second if statement. There is a function 

!Functions.IsPursuitStillRunning(Pursuit)

and because new GameFiber is still sleeping and blocking to assign 

Functions.CreatePursuit();

to varible Pursuit, we have Pursuit equals null. And we can't execute the function IsPursuitStillRunning(). That is why I had an error.

Case closed!

Link to comment
Share on other sites

  • Management Team

You should also make sure to only spawn your new GameFiber once. Not sure if you omitted code, but in your snippet above it looks like a new fiber (and hence a new thread) will be spun up every tick.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

Link to comment
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.



×
×
  • Create New...