Skip to content

Mono: Calling GameplayCamera.Matrix causes a NullReferenceException (b1604+b2545) #1884

Open
@justalemon

Description

@justalemon

I was trying to use World.GetCrosshairCoordinates and I stumbled upon a NullReferenceException when calling said function. I was able to trace back this exception to the Matrix property of GameplayCamera thanks to this test code:

using System.Threading.Tasks;
using CitizenFX.Core;

namespace MatrixTesting.Client;

public class Testing : BaseScript
{
    public Testing()
    {
        Tick += OnTick;
    }

    private async Task OnTick()
    {
        Matrix matrix = GameplayCamera.Matrix;
    }
}

Which will produce the following exception:

[    614438] [b2545_GTAProce]             MainThrd/ Failed to run a tick for Testing: System.NullReferenceException: Object reference not set to an instance of an object
[    614438] [b2545_GTAProce]             MainThrd/   at System.Buffer.memcpy4 (System.Byte* dest, System.Byte* src, System.Int32 size) [0x00002] in <4a74a468ceae4b8199f7400d96d8dff5>:0 
[    614438] [b2545_GTAProce]             MainThrd/   at System.Buffer.Memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) [0x00073] in <4a74a468ceae4b8199f7400d96d8dff5>:0 
[    614438] [b2545_GTAProce]             MainThrd/   at System.String.memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) [0x00000] in <4a74a468ceae4b8199f7400d96d8dff5>:0 
[    614438] [b2545_GTAProce]             MainThrd/   at (wrapper unknown) CitizenFX.Core.Matrix:PtrToStructure (intptr,object)
[    614438] [b2545_GTAProce]             MainThrd/   at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:PtrToStructure (intptr,System.Type)
[    614438] [b2545_GTAProce]             MainThrd/   at System.Runtime.InteropServices.Marshal.PtrToStructure[T] (System.IntPtr ptr) [0x00000] in <4a74a468ceae4b8199f7400d96d8dff5>:0 
[    614438] [b2545_GTAProce]             MainThrd/   at CitizenFX.Core.Native.MemoryAccess.ReadMatrix (System.IntPtr pointer) [0x00000] in C:\gl\builds\master\fivem\code\client\clrcore\Native.cs:181 
[    614438] [b2545_GTAProce]             MainThrd/   at CitizenFX.Core.GameplayCamera.get_Matrix () [0x00000] in C:\gl\builds\master\fivem\code\client\clrcore\External\Camera.cs:551 
[    614438] [b2545_GTAProce]             MainThrd/   at MatrixTesting.Client.Testing+<OnTick>d__1.MoveNext () [0x00008] in D:\Proyectos\Testing\MatrixTesting\MatrixTesting.Client\Testing.cs:15 

I tested game build 2545, I'm not sure if this can be replicated with other game versions.

If more information is needed, feel free to let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ScRT: C#Issues/PRs related to either C# scripting runtimes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions