assettocorsasharedmemory icon indicating copy to clipboard operation
assettocorsasharedmemory copied to clipboard

Getting the status of the game/sim

Open ikkennigij121 opened this issue 3 years ago • 2 comments

Hello,

I'm trying to figure out how to get the status of the race by using AC_STATUS in following manner. Bare in mind it's very simplistic as I'm discovering how it works:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AssettoCorsaSharedMemory;

namespace ACplayground
{
    class Program
    {
        static void Main(string[] args)
        {
            AssettoCorsa ac = new AssettoCorsa();
            ac.Start();

            ac.GraphicsUpdated += Ac_GraphicsUpdated;

            Console.ReadKey();
        }

        private static void Ac_GraphicsUpdated(object sender, GraphicsEventArgs e)
        {
            Console.WriteLine(e.Graphics.Status);
        }

    }
}

I'm getting a null reference exception pointing to following code:

public virtual void OnGraphicsUpdated(GraphicsEventArgs e)
        {
            if (GraphicsUpdated != null)
            {
                GraphicsUpdated(this, e);
                if (gameStatus != e.Graphics.Status)
                {
                    gameStatus = e.Graphics.Status;
                    GameStatusChanged(this, new GameStatusEventArgs(gameStatus));   //This part is highlighted
                }
            }
        }

The console writes one line of the status, after which it throws the exception.

any idea what can be the cause?

Kind regards

ikkennigij121 avatar Apr 14 '21 10:04 ikkennigij121

Additional note: as soon as the status changes from AC_OFF to AC_LIVE the exception is thrown. issue

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=AssettoCorsaSharedMemory
  StackTrace:
   at AssettoCorsaSharedMemory.AssettoCorsa.OnGraphicsUpdated(GraphicsEventArgs e) in D:\Texture Pack\assettocorsasharedmemory-master\AssettoCorsa.cs:line 223

D:\Texture Pack\ is just the location I saved the sharedmemory masterfile where the referenced DLL is located.

ikkennigij121 avatar Apr 14 '21 17:04 ikkennigij121

@ikkennigij121 there is an issue with this library, where it assumes the event "GameStatusChanged" of type "GameStatusChangedHandler" has a subscriber.

My recommendation would be to comment out the line GameStatusChanged(this, new GameStatusEventArgs(gameStatus)); And obtain the game status directly from the Graphics like you are doing.

Ralms avatar May 11 '21 18:05 Ralms

@ikkennigij121 I fixed this in https://github.com/mdjarv/assettocorsasharedmemory/pull/15

corygrant avatar Jan 09 '23 00:01 corygrant

@ikkennigij121 I fixed this in #15

Cheers!

ikkennigij121 avatar Jan 09 '23 13:01 ikkennigij121