Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple calls to GetInput extension lead to new glfw input contexts #80

Closed
Pyrdacor opened this issue Dec 22, 2019 · 7 comments · Fixed by #86 or #97
Closed

Multiple calls to GetInput extension lead to new glfw input contexts #80

Pyrdacor opened this issue Dec 22, 2019 · 7 comments · Fixed by #86 or #97
Labels
area-Input bug Something isn't working

Comments

@Pyrdacor
Copy link
Collaborator

Summary

Multiple calls to the GetInput extension will create a new glfw input context each time. Therefore event registering on other than the first input context will not raise the events.

Steps to reproduce

  • Platform: Any
  • Framework Version: Any
  1. Create one method for initialize keyboard events and one for initialize mouse events.
  2. In each method use GetInput() to retrieve the input context and add event handlers for keyboard events (first method) and mouse events (second method).
  3. Mouse event callbacks are not called as the used input context is not considered by Silk. Only the first one is.

The problem is the method GetInput below. It creates a new instance of the input context instead of reusing the existing one if present.

    public class GlfwInputPlatform : IInputPlatform
    {
        public bool IsApplicable(IWindow window)
        {
            return window is GlfwWindow;
        }

        public IInputContext GetInput(IWindow window)
        {
            // the cast isn't needed, but is used to make sure that what we've got is actually a GlfwWindow
            return new GlfwInputContext((GlfwWindow)window); // <- Problem, should reuse context when called for the second time
        }
    }

Possible solutions

  • Reuse context on second and subsequent calls
  • Documentation that each time it is called a new context is created (in this case rename to CreateInput)
  • Make Silk register each of the created contexts and ensure that all of them are handled

I would prefer first fix.

@Pyrdacor Pyrdacor added the bug Something isn't working label Dec 22, 2019
@Pyrdacor Pyrdacor changed the title Multiple calls to GetInput extensions leads to new glfw input contexts Multiple calls to GetInput extension lead to new glfw input contexts Dec 22, 2019
@Perksey
Copy link
Member

Perksey commented Dec 22, 2019

This is by design, you should really only be calling GetInput once and keeping track of the input context.

@Perksey Perksey added the wontfix This will not be worked on label Dec 22, 2019
@Perksey
Copy link
Member

Perksey commented Dec 22, 2019

Although I guess we could change it, idk @Ultz/silk-working-group what do you think?

@Pyrdacor
Copy link
Collaborator Author

Pyrdacor commented Dec 22, 2019

If you want to keep it this way, then this has to be documented better. Moreover a method labeled "GetXYZ" should have no side-effects by design. I would not expect that a new context is created. This should be renamed to CreateInput imho. With CreateInput I would expect a new context. But even then this context should be registered and it is not, or am I missing something?

@Perksey
Copy link
Member

Perksey commented Dec 22, 2019

Yeah I 100% agree with you. The only reason we purposely made it so that it creates a new context is we wanted to avoid people going window.GetInput().blah for every single input call as that’s a code smell.

@Perksey Perksey removed the wontfix This will not be worked on label Dec 22, 2019
@Perksey
Copy link
Member

Perksey commented Dec 22, 2019

I’ll put it up to an working group vote now.

@Pyrdacor
Copy link
Collaborator Author

You can rename it to CreateInput to avoid your mentioned case.

@Perksey
Copy link
Member

Perksey commented Jan 5, 2020

This was prematurely closed as this change was not implemented in InputWindowExtensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Input bug Something isn't working
Projects
None yet
2 participants