Skip to content

Invoke function is broken #2597

Description

@Losi-pl

Summary

When trying to use the Invoke function from IView i receive an error message.

Steps to reproduce

  • Platform: Desktop
  • Framework Version: .NET 10
  • Silk.NET Version: 2.23.0
  • API: OpenGL
  • API Version: OpenGL 4.6 Core

Initiation:

var initOptions = WindowOptions.Default with
{
    IsVisible = false,
    VSync = false,
    Size = new(1280, 720), 
    API = new GraphicsAPI
    {
        API = ContextAPI.OpenGL,
        Profile = ContextProfile.Compatability,
        Flags = ContextFlags.ForwardCompatible,
        Version = new APIVersion(4, 6)
    },
    FramesPerSecond = 60
};

Issue

Code

Task.Run(() =>
{
    Thread.Sleep(100);
    Window.Main.MeGLFW.Invoke(() => Console.WriteLine("error"));
});

Errors

On the main Thread:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Silk.NET.Windowing.Internals.ViewImplementationBase.DoInvokes()
   at Silk.NET.Windowing.Internals.ViewImplementationBase.DoRender()
   at Silk.NET.Windowing.WindowExtensions.<>c__DisplayClass2_0.<Run>b__0()
   at Silk.NET.Windowing.Internals.ViewImplementationBase.Run(Action onFrame)
   at Silk.NET.Windowing.Glfw.GlfwWindow.Run(Action onFrame)
   at Silk.NET.Windowing.WindowExtensions.Run(IView view)
   at /* My App Init */

And in the Task:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Silk.NET.Windowing.Internals.ViewImplementationBase.Invoke(Delegate d, Object[] args)
   at /* Task.Run() */
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
public object Invoke(Delegate d, params object[] args)
{
    var rentalIndex = Interlocked.Increment(ref _rented) - 1;
    EnsureArrayIsReady(rentalIndex);
    ref var x = ref _pendingInvocations![rentalIndex];
    x.Delegate = d;
    x.Data = args;
    x.ResetEvent.Reset(); // <- Here
    x.IsComplete = false;
    x.ResetEvent.Wait();
    var ret = x.Data[0];
    _returnArrayPool.Return(x.Data);
    x.Delegate = null;
    x.Data = null;
    return ret;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions