Search Unity

Native Window and Editor

Discussion in 'Windows' started by codingstyle, Oct 11, 2017.

  1. codingstyle

    codingstyle

    Joined:
    Jan 2, 2017
    Posts:
    3
    Hello,

    I am working on a Unity native plugin using Win32 APIs to render a webview component on a texture.

    To achieve that, I am creating a separate native window with its own handle. My window class is registered with style CS_HREDRAW | CS_VREDRAW, window is then created with style WS_CAPTION.

    With a standalone build of my project, things work fine. But in Unity Editor, the native window doesn't seem to update, repaint, or process any message until I start moving it manually.

    Is there any tip regarding usage of native windows with Unity standalone app/editor I'm missing?

    Regards,
    Chris
     
    ChernovAnton likes this.
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    Is it your window that does not repaint or one of the editor windows? What thread do you create your window on, and are you pumping window messages?
     
  3. codingstyle

    codingstyle

    Joined:
    Jan 2, 2017
    Posts:
    3
    Problem affects my custom window. Editor and standalone windows work normally.

    Window is created during a kUnityGfxDeviceEventInitialize event, but the documentation isn't explicit whether it is executed in the same thread as editor window or not.

    To pump window messages, I use a method called every frame through a GL.IssuePluginEvent() - therefore, on the render thread.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,675
    That doesn't sound like a good idea: the game loop isn't running when the editor is not in play mode, and I suspect it will make your window stuck since window messages won't be pumped.

    You should instead create a dedicated thread (using native CreateThread or C# System.Threading.Thread), create your window on that thread and pump the messages in a loop until you need to close your window.
     
    codingstyle likes this.