glfw-net icon indicating copy to clipboard operation
glfw-net copied to clipboard

Glfw.GetKeyName(Keys key, int scanCode) throws internal exception when used with non-printable key

Open SuperS1405 opened this issue 5 years ago • 2 comments

Glfw.GetKeyName(Keys key, int scanCode) throws an internal NullReferenceException when specifying a key that is non-printable (eg. Keys.LeftControl). Description states the method returnes null instead. To fix this, changing

public static string GetKeyName(Keys key, int scanCode)
{
    return Util.PtrToStringUTF8(GetKeyNameInternal(key, scanCode));
}

to

public static string GetKeyName(Keys key, int scanCode)
{
    IntPtr ptr = GetKeyNameInternal(key, scanCode);
    return ptr == IntPtr.Zero? null : Util.PtrToStringUTF8(ptr);
 }

should probably do the trick.

Side note: what are the plans on releasing the current/corrected version to nuget?

SuperS1405 avatar May 27 '20 15:05 SuperS1405

Thanks, will fix that too,

Am finally working on this again right now (literally).

ForeverZer0 avatar May 27 '20 17:05 ForeverZer0

Awesome! Allow me to thank you for all the time you put into this - making bindings is a pain (I am one to talk, you would know xD), so this makes a lot of peoples life significantly easier. We appreciate it!

SuperS1405 avatar May 27 '20 19:05 SuperS1405