assettocorsasharedmemory
assettocorsasharedmemory copied to clipboard
Getting the status of the game/sim
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
Additional note: as soon as the status changes from AC_OFF to AC_LIVE the exception is thrown.
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 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.
@ikkennigij121 I fixed this in https://github.com/mdjarv/assettocorsasharedmemory/pull/15
@ikkennigij121 I fixed this in #15
Cheers!