Exception thrown with auxiliary keyboard keys and knobs
CalvinWilkinson opened this issue ยท 11 comments
Summary
When using auxiliary keys or knobs on a keyboard, the application crashes. At first, I thought it was something in my library Velaptor, but after some investigation, I discovered that an InvalidOperationException is being thrown from the Reset() method in the ViewImplementationBase abstract class in the Silk.NET.Windowing.Internals namespace.
I know this is because I looked into the internal exception being thrown in Velaptor, and the exception message is You cannot call 'Reset' inside of the render loop!. I found this by searching in the Silk source code for tag v2.22.0.
When I say 'auxiliary', I mean custom keyboard keys and knobs that are used for volume, mute, skipping songs, etc.
I have a mechanical keyboard and my laptop keyboard, which have some aux keys and/or knobs that cause the exception to be thrown.
Since Velaptor is open source, you can run the VelaptorTesting project. Once the window is displayed, adjust the audio knob on a keyboard that has one, and it should crash. I attempted to see if the problem would occur in the Imgui sample project, but I had issues with errors being thrown by nuke. I am confident you can reproduce the issue with the Silk example projects.
I subscribe to a keyboard key-down event of an IInputContext instance. I set a breakpoint in my event handler, but it is not invoked. It simply immediately throws an exception.
Steps to reproduce
- Platform: Desktop
- Framework Version: dotnet 9.0
- API: OpenGL
- API Version: OpenGL 4.5 Core
- Open the solution for the latest version tag of Velaptor or a Silk sample project.
- Run the VelaptorTesting project or a Silk sample project
- Adjust the volume knob or hit an aux key on a keyboard that has a this functionality.
- Observe that an exception is thrown.
Comments
The screenshots below are the knobs and keys that are causing the exception:


More Info:
- MONTECH Mechanical Keyboard
- [Asus ROG Zephyrus G16 Laptop](I know this is because I looked into the internal exception being thrown in Velaptor, and the exception message is
You cannot call 'Reset' inside of the render loop!. I found this by searching in the Silk source code for tagv2.22.0.)
Note
This is not just a volume knob. It can be used for other functions on the keyboard, such as the lighting.
Hitting the volume up and down on my laptop keyboard causes the same issue.
If you need more information or testing, let me know, and I would be glad to help. Thanks!!
If you know how to fix this issue, please submit a pull request instead!
Do you have a stack trace
Sure thing @Perksey
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: You cannot call `Reset` inside of the render loop!
at Silk.NET.Windowing.Internals.ViewImplementationBase.Reset()
at Silk.NET.Windowing.Internals.ViewImplementationBase.Dispose()
at InvokeStub_IDisposable.Dispose(Object, Object, IntPtr*)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--- End of inner exception stack trace ---
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Velaptor.InternalExtensionMethods.DisposeOfType(Container container, Type type) in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\InternalExtensionMethods.cs:line 248
at Velaptor.IoC.DisposeOfRegisteredTypes() in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\IoC.cs:line 91
at Velaptor.UI.Window.DisposeOfRegisteredTypes() in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\UI\Window.cs:line 302
at Velaptor.UI.Window.Dispose(Boolean disposing) in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\UI\Window.cs:line 295
at Velaptor.UI.Window.Dispose() in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\UI\Window.cs:line 199
at VelaptorTesting.Program.Main(String[] args) in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Testing\VelaptorTesting\Program.cs:line 101
at VelaptorTesting.Program.<Main>(String[] args)Here's another update: I just ran into the same issue again, but this time, it had nothing to do with keyboard input.
The application quits so quickly that I could barely get a screenshot.
This time, it is thrown when I tried to run a Manual Testing Application after doing a publish using the dotnet command dotnet publish -c Release -r win-x64. This application has various "scenes" and only crashes when it loads the audio scene to test the audio. All of the other scenes operate as expected.
Standard Debug and Release builds from Rider does not cause any issues.
I cannot repeat the problem when running as Debug or Release in Rider. It only crashes with that exception when running the published app.
I even wrapped the entire code in the main method to see if I could catch an exception and then write it out to a file, but this does not work. It just simply crashes.
Do you have any insight into what this exception from SILK means and what might cause it?
I am also looking into other avenues on my side but so far I have not found anything.
It is highly likely it's threading issues. I'm not prepared to audit the codebase's async usage but it seems very consistent with threading issues.
It is highly likely it's threading issues. I'm not prepared to audit the codebase's async usage but it seems very consistent with threading issues.
Ok. Let me know if there is something that you want me to do or try out when you guys get to the point of trying to troubleshoot/fix the issue.
@Perksey
Quick update.
- When running from Rider, everything works fine.
- When running from disk when doing a
dotnet publish -c Release -r win-x64, its fails. - I tried the following silk version below to see if the issue would go aways with no success:
- 2.22.0
- 2.21.0
- 2.20.0
- 2.19.0
- 2.18.0
- 2.17.1
- 2.0.0
I am on Windows 11.
I think a good start would be to establish a minimum reproduction outside of your framework and its async shenanigans. I'm pretty confident it's your usage of async that's causing issues, but if this reproduces outside of this environment then this indicates it's a Silk.NET issue.
I am currently in the process of doing some elimination work now.
I am not using any async in my library. At least, not that I know of. One of the things I am looking into. I will report back with some findings.
I think I partially figured out what is going on.
When trying to reproduce the error in my library Velaptor, I got a different exception, but by doing the same
keyboard action by twisting the knob that I originally reported.
The original exception that I reported was:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: You cannot call `Reset` inside of the render loop!
at Silk.NET.Windowing.Internals.ViewImplementationBase.Reset()
at Silk.NET.Windowing.Internals.ViewImplementationBase.Dispose()
at InvokeStub_IDisposable.Dispose(Object, Object, IntPtr*)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--- End of inner exception stack trace ---
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Velaptor.InternalExtensionMethods.DisposeOfType(Container container, Type type) in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\InternalExtensionMethods.cs:line 248
at Velaptor.IoC.DisposeOfRegisteredTypes() in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\IoC.cs:line 91
at Velaptor.UI.Window.DisposeOfRegisteredTypes() in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\UI\Window.cs:line 302
at Velaptor.UI.Window.Dispose(Boolean disposing) in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\UI\Window.cs:line 295
at Velaptor.UI.Window.Dispose() in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Velaptor\UI\Window.cs:line 199
at VelaptorTesting.Program.Main(String[] args) in K:\SOFTWARE-DEVELOPMENT\PERSONAL\Velaptor\Testing\VelaptorTesting\Program.cs:line 101
at VelaptorTesting.Program.<Main>(String[] args)This time I got the following exception:
System.NotImplementedException: The method or operation is not implemented.
at Silk.NET.OpenGL.Extensions.ImGui.ImGuiController.TranslateInputKeyToImGuiKey(Key key)
at Silk.NET.OpenGL.Extensions.ImGui.ImGuiController.OnKeyEvent(IKeyboard keyboard, Key keycode, Int32 scancode, Boolean down)
at Silk.NET.OpenGL.Extensions.ImGui.ImGuiController.OnKeyDown(IKeyboard keyboard, Key keycode, Int32 scancode)
at Silk.NET.Input.Glfw.GlfwKeyboard.<Subscribe>b__33_1(WindowHandle* _, Keys key, Int32 code, InputAction action, KeyModifiers mods)
at Silk.NET.Input.Glfw.GlfwEvents.<.ctor>b__0_1(WindowHandle* a, Keys b, Int32 c, InputAction d, KeyModifiers e)
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 Program.<Main>$(String[] args) in K:\SOFTWARE-DEVELOPMENT\TESTING\VelKeyIssue\VelKeyIssue\Program.cs:line 40Based on the information of the new exception, I wanted to try and repeat the issue by creating a minimal silk
application. Velaptor uses the ImGuiController. So I brought over all of the related code to the minimal silk
app to try and reproduce it there. I was able to successfully repeat the same issue.
So I went into the source code for the ImGuiController class from silk and in the TranslateInputKeyToImGuiKey() method
to discover the reason for the NotImplementedException being thrown. The twisting of the knob as well as the other
keys on my laptop produces a key that does not match any of the switch cases, hence the exception.
I don't know if this might help you out, but I don't know why the exceptions are different.
If you are interested, here is the minimal silk project.
Cheers!
Ah okay, in which case this is a duplicate of #2372 which is awaiting contributions. Nice work figuring it out :)
Ah okay, in which case this is a duplicate of #2372 which is awaiting contributions. Nice work figuring it out :)
Ah ok. It's good to know something is out there for it. Thx for taking the time! ๐