SimulaVR / Simula

Linux VR Desktop
MIT License
2.91k stars 87 forks source link

Upgrade Simula to Godot 3.1 to improve godot_openvr stability #88

Closed georgewsinger closed 4 years ago

georgewsinger commented 4 years ago

There are at least two significant godot_openvr issues that are making Simula unstable. Their progress can be viewed here:

These stability issues are, in my opinion, the most important barriers keeping Simula from being actively usable as a VR window manager.

georgewsinger commented 4 years ago

Upgrading to Godot 3.1. The first step to fixing these godot_openvr stability issues is upgrading our dependency to Godot 3.1. This immediately yields gdwlroots compilation issues:

git clone --branch "3.1" --recursive https://github.com/godotengine/godot godot3.1
cd godot3.1
cd modules
git clone --branch xwayland --recursive https://github.com/SimulaVR/gdwlroots gdwlroots
cd gdwlroots
make all
cd ../..
scons platform=x11 target=debug -j 8

yields

modules/gdwlroots/wlr_backend.cpp:3:10: fatal error: servers/visual/
visual_server_global.h: No such file or directory                  
 #include "servers/visual/visual_server_global.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
scons: *** [modules/gdwlroots/wlr_backend.x11.tools.64.o] Error 1
scons: building terminated because of errors.

I'll report back once I get gdwlroots working with Godot 3.1.

georgewsinger commented 4 years ago

:heavy_check_mark: Got gdwlroots working with Godot 3.1, but now having trouble compiling Simula itself:

In file included from /usr/local/include/wlr/types/wlr_xdg_shell.h:14,

/home/george/Simula3.1/addons/godot-haskell-plugin/                 from /tmp/ghc15860_0/ghc_8.c:42:0: error: 

/home/george/Simula3.1/addons/godot-haskell-plugin/include/xdg-shell-protocol.h:867:0: error:
     error: unterminated #ifndef   
     #ifndef XDG_TOPLEVEL_STATE_ENUM

    |                              
867 | #ifndef XDG_TOPLEVEL_STATE_ENUM
    | ^                            
In file included from /usr/local/include/wlr/types/wlr_xdg_shell.h:14,

/home/george/Simula3.1/addons/godot-haskell-plugin/                 from /tmp/ghc15860_0/ghc_8.c:42:0: error: 

/home/george/Simula3.1/addons/godot-haskell-plugin/include/xdg-shell-protocol.h:3:0: error:
     error: unterminated #ifndef   
     #ifndef XDG_SHELL_SERVER_PROTOCOL_H

  |                                
3 | #ifndef XDG_SHELL_SERVER_PROTOCOL_H
  | ^                              
`gcc' failed in phase `C Compiler'. (Exit code: 1)
Completed 10 action(s).            

Note these are ghc errors^

georgewsinger commented 4 years ago

I am able to get gdwlroots + godot-haskell-gdwlroots + Simula to compile with Godot 3.1; however, I'm getting the following run-time error when launching:

ERROR: set_msaa: Index p_msaa=8 out of size (5=5)
   At: scene/main/viewport.cpp:2829.
Haskell GDNative initialized
libGodotHaskellPlugin.so: Unknown API struct type 5
CallStack (from HasCallStack):
  error, called at src/Godot/Gdnative/Internal/Gdnative.chs:783:12 in godot-haskell-3.1.0.0-2fLCyvlk4a1LWwJbEUJ90a:Godot.Gdnative.Internal.Gdnative
P1R : warning: too many hs_exit()s
make[1]: *** [Makefile:18: run] Error 1
make[1]: Leaving directory '/home/george/Simula/addons/godot-haskell-plugin'
/home/george/Simula
georgewsinger commented 4 years ago

Some updates:

I'm fighting through both of these issues at present.

georgewsinger commented 4 years ago

godot-haskell signal registering. I'm getting run-time errors when trying to register signals against Godot 3.1/godot-haskell:

instance NativeScript GodotSimulaViewSprite where
  className = "SimulaViewSprite"
  classInit obj =
    GodotSimulaViewSprite (safeCast obj)
                  <$> atomically (newTVar (error "Failed to initialize GodotSimulaViewSprite."))
                  <*> atomically (newTVar True)
                  <*> atomically (newTVar (error "Failed to initialize GodotSimulaViewSprite."))
                  <*> atomically (newTVar (error "Failed to initialize GodotSimulaViewSprite."))
                  <*> atomically (newTVar (error "Failed to initialize GodotSimulaViewSprite."))
                  <*> atomically (newTVar (error "Failed to initialize GodotSimulaViewSprite."))
                  -- <*> atomically (newTVar False)
  -- classExtends = "RigidBody"
  classMethods =
    [ func NoRPC "_input_event" inputEvent
    , func NoRPC "_ready" ready

    , func NoRPC "_handle_destroy" _handle_destroy -- Connected in SimulaServer.hs
    , func NoRPC "_handle_map" _handle_map         -- Connected in SimulaServer.hs
    , func NoRPC "_process" Plugin.SimulaViewSprite._process
    , func NoRPC "_handle_unmap" _handle_unmap     -- Connected in SimulaServer.hs
    ]

  -- Test:
  classSignals = [ signal "map" [("gsvs", GodotVariantTypeObject)]
                 , signal "unmap" [("gsvs", GodotVariantTypeObject)]
                 ]
Registering class SimulaViewSprite
Registering method _input_event to class SimulaViewSprite
Registering method _ready to class SimulaViewSprite
Registering method _handle_destroy to class SimulaViewSprite
Registering method _handle_map to class SimulaViewSprite
Registering method _process to class SimulaViewSprite
Registering method _handle_unmap to class SimulaViewSprite
ERROR: godot_nativescript_register_signal: Attempted to register method on non-existent class!
   At: modules/gdnative/nativescript/godot_nativescript.cpp:154.
Registering signal map to class SimulaViewSprite
ERROR: godot_nativescript_register_signal: Attempted to register method on non-existent class!
   At: modules/gdnative/nativescript/godot_nativescript.cpp:154.
Registering signal unmap to class SimulaViewSprite

with

void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal) {

    String *s = (String *)p_gdnative_handle;

    Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);

    if (!E) {
        ERR_EXPLAIN("Attempted to register method on non-existent class!");
        ERR_FAIL();
    }
//..
}
georgewsinger commented 4 years ago

Full run-time crash with gdb debug report. Very strange.

Registering method _input_event to class SimulaViewSprite
Registering method _ready to class SimulaViewSprite
Registering method _handle_destroy to class SimulaViewSprite
Registering method _handle_map to class SimulaViewSprite
Registering method _process to class SimulaViewSprite
Registering method _handle_unmap to class SimulaViewSprite
ERROR: godot_nativescript_register_signal: Attempted to register method on non-existent class!
   At: modules/gdnative/nativescript/godot_nativescript.cpp:154.
Registering signal map to class SimulaViewSprite
ERROR: godot_nativescript_register_signal: Attempted to register method on non-existent class!
   At: modules/gdnative/nativescript/godot_nativescript.cpp:154.
Registering signal unmap to class SimulaViewSprite
OpenVR: initialising OpenVR context
ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred
warning: Corrupted shared library list: 0x6eca840 != 0x6eadcc0
Sun Sep 22 2019 19:30:35.176294 - //==============================================================================================
Sun Sep 22 2019 19:30:35.176341 - ================================================================================================
Sun Sep 22 2019 19:30:35.176383 - ================================================================================================
Sun Sep 22 2019 19:30:35.176413 - godot 1.7.15 startup with PID=5912, config=/home/george/.steam/steam/config, runtime=/home/george/.steam/steam/steamapps/common/SteamVR
Sun Sep 22 2019 19:30:35.176444 - vrclient type=VRApplication_Scene
Sun Sep 22 2019 19:30:35.177146 - [Settings] Load Default Json Settings from /home/george/.steam/steam/steamapps/common/SteamVR/drivers/htc/resources/settings/default.vrsettings
Sun Sep 22 2019 19:30:35.177237 - [Settings] Load Default Json Settings from /home/george/.steam/steam/steamapps/common/SteamVR/drivers/lighthouse/resources/settings/default.vrsettings
Sun Sep 22 2019 19:30:35.177305 - [Settings] Load Default Json Settings from /home/george/.steam/steam/steamapps/common/SteamVR/drivers/null/resources/settings/default.vrsettings
Sun Sep 22 2019 19:30:35.177482 - [Settings] Load Default Json Settings from /home/george/.steam/steam/steamapps/common/SteamVR/resources/settings/default.vrsettings
Sun Sep 22 2019 19:30:35.177913 - [Settings] Load Json Settings from /home/george/.steam/steam/config/steamvr.vrsettings
[Detaching after vfork from child process 5935]
Sun Sep 22 2019 19:30:35.185454 - CIPCPipe::ConnectPipe(SteamVR_Namespace) attempting connect to steamvr:SteamVR_Namespace
Sun Sep 22 2019 19:30:35.185561 - CSharedResourceNamespaceClient::Init(): received namespace data 3672
Sun Sep 22 2019 19:30:35.185602 - CIPCPipe::ConnectPipe(VR_ServerPipe_3672) attempting connect to steamvr:VR_ServerPipe_3672
Sun Sep 22 2019 19:30:35.186899 - Received connect response VRInitError_Init_AnotherAppLaunching. Giving up.
[Detaching after vfork from child process 5939]
Unable to init VR runtime: Another app was already launching (117)
Compositor initialization failed. See log file for details.
OpenVR: releasing OpenVR context
Failed to initialize VR interface.
Running Wayland server on display simula-0
2019-09-22 19:30:35 - [xwayland/sockets.c:47] Failed to bind socket @/tmp/.X11-unix/X0: Address already in use
2019-09-22 19:30:35 - [xwayland/sockets.c:47] Failed to bind socket @/tmp/.X11-unix/X1: Address already in use
[Detaching after fork from child process 5941]
New DISPLAY=:2
2019-09-22 19:30:35 - [xwayland/xwayland.c:103] WAYLAND_SOCKET=29 Xwayland :2 -rootless -terminate -listen 27 -listen 28 -wm 31
glamor: 'wl_drm' not supported
Missing Wayland requirements for glamor GBM backend
Failed to initialize glamor, falling back to sw
2019-09-22 19:30:35 - [types/wlr_surface.c:595] New wlr_surface 0x6f4f660 (res 0x6f13720)
2019-09-22 19:30:35 - [modules/gdwlroots/wlr_surface.cpp:103] Created surface 0x755c0b0 for 0x6f4f660
2019-09-22 19:30:35 - [xwayland/xwayland.c:353] sent SIGUSR1 to process 5912

Thread 5 "godot" received signal SIGUSR1, User defined signal 1.
[Switching to Thread 0x7fffedc22700 (LWP 5925)]
0x00007ffff70c6670 in __GI___nanosleep (requested_time=requested_time@entry=0x7fffedc21b70, 
    remaining=remaining@entry=0x0) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28  ../sysdeps/unix/sysv/linux/nanosleep.c: No such file or directory.
(gdb) bt
#0  0x00007ffff70c6670 in __GI___nanosleep
    (requested_time=requested_time@entry=0x7fffedc21b70, remaining=remaining@entry=0x0)
    at ../sysdeps/unix/sysv/linux/nanosleep.c:28
#1  0x00007ffff70f9894 in usleep (useconds=<optimized out>) at ../sysdeps/posix/usleep.c:32
#2  0x00000000011b526f in JoypadLinux::monitor_joypads() (this=0x5e59d00)
    at platform/x11/joypad_linux.cpp:217
#3  0x00000000011b5170 in JoypadLinux::run_joypad_thread() (this=0x5e59d00)
    at platform/x11/joypad_linux.cpp:115
#4  0x00000000011b5153 in JoypadLinux::joy_thread_func(void*) (p_user=0x5e59d00)
    at platform/x11/joypad_linux.cpp:102
#5  0x0000000001b487a1 in ThreadPosix::thread_callback(void*) (userdata=0x5e6add0)
    at drivers/unix/thread_posix.cpp:74
#6  0x00007ffff763e182 in start_thread (arg=<optimized out>) at pthread_create.c:486
#7  0x00007ffff7102b1f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

@lboklin Have you encountered anything like this before?

georgewsinger commented 4 years ago

Commenting out the call to register GodotSimulaViewSprite still yields a Simula crash. The following

registerClasses :: GdnativeHandle -> IO ()
registerClasses desc = do
  let reg constr = registerClass $ RegClass desc constr
  reg $ classInit @GodotSimula
  reg $ classInit @GodotSimulaController
  reg $ classInit @GodotSimulaServer
  -- reg $ classInit @GodotSimulaViewSprite -- ⟵ Comment out the problematic class

still yields

Missing Wayland requirements for glamor GBM backend
Failed to initialize glamor, falling back to sw
2019-09-23 14:48:32 - [types/wlr_surface.c:595] New wlr_surface 0x6f54080 (res 0x6f543a0)
2019-09-23 14:48:32 - [modules/gdwlroots/wlr_surface.cpp:103] Created surface 0x755b240 for 0x6f54080
2019-09-23 14:48:32 - [xwayland/xwayland.c:353] sent SIGUSR1 to process 13544

Thread 5 "godot" received signal SIGUSR1, User defined signal 1.
[Switching to Thread 0x7fffedc22700 (LWP 13557)]
0x00007ffff70c6670 in __GI___nanosleep (requested_time=requested_time@entry=0x7fffedc21b70, remaining=remaining@entry=0x0) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28  ../sysdeps/unix/sysv/linux/nanosleep.c: No such file or directory.
(gdb) bt
#0  0x00007ffff70c6670 in __GI___nanosleep (requested_time=requested_time@entry=0x7fffedc21b70, remaining=remaining@entry=0x0) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
#1  0x00007ffff70f9894 in usleep (useconds=<optimized out>) at ../sysdeps/posix/usleep.c:32
#2  0x00000000011b526f in JoypadLinux::monitor_joypads() (this=0x5e5a090) at platform/x11/joypad_linux.cpp:217
#3  0x00000000011b5170 in JoypadLinux::run_joypad_thread() (this=0x5e5a090) at platform/x11/joypad_linux.cpp:115
#4  0x00000000011b5153 in JoypadLinux::joy_thread_func(void*) (p_user=0x5e5a090) at platform/x11/joypad_linux.cpp:102
#5  0x0000000001b487a1 in ThreadPosix::thread_callback(void*) (userdata=0x5e6b160) at drivers/unix/thread_posix.cpp:74
#6  0x00007ffff763e182 in start_thread (arg=<optimized out>) at pthread_create.c:486
#7  0x00007ffff7102b1f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

so those ERROR: godot_nativescript_register_signal messages might not matter.

georgewsinger commented 4 years ago

:heavy_check_mark: After incorporating @KaneTW's SIGUSR1 patch, Simula + Godot3.1 (Simula3.1 for short) no longer experiences the above error. I'm now getting a bunch of run-time errors related to the godot-extra/godot-haskell changes, and sorting through them accordingly.

I just pushed the code to a new 3.1 branch of SimulaVR/godot.

georgewsinger commented 4 years ago

godot-3.1 branch. I just threw up a godot-3.1 branch with the code I'm working with.

Simula runs w/Godot 3.1 but with signal registering errors. In particular, the "map" signal never gets registered, so when programs are launched sprites never become visible. The specific error:

Registering class SimulaViewSprite
Registering method _input_event to class SimulaViewSprite
Registering method _ready to class SimulaViewSprite
Registering method _handle_destroy to class SimulaViewSprite
Registering method _handle_map to class SimulaViewSprite
Registering method _process to class SimulaViewSprite
Registering method _handle_unmap to class SimulaViewSprite
ERROR: godot_nativescript_register_signal: Attempted to register method on non-existent class!
    At: modules/gdnative/nativescript/godot_nativescript.cpp:154.
Registering signal map to class SimulaViewSprite
ERROR: godot_nativescript_register_signal: Attempted to register method on non-existent class!
    At: modules/gdnative/nativescript/godot_nativescript.cpp:154.
Registering signal unmap to class SimulaViewSprite

# ...

putStrLn: SimulaViewSprite Constructor called
ERROR: connect: In Object of type 'RigidBody': Attempt to connect nonexistent signal 'map' to method 'Spatial.handle_map_surface'
    At: core/object.cpp:1463.
ERROR: connect: In Object of type 'RigidBody': Attempt to connect nonexistent signal 'unmap' to method 'Spatial.handle_unmap_surface'
    At: core/object.cpp:1463.

# ..

_handle_map
ERROR: emit_signal: Can't emit non-existing signal "map".
    At: core/object.cpp:1172.

Here is the relevant code snippet from godot-haskell. Here is the error being triggered from godot:

void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal) {

    String *s = (String *)p_gdnative_handle;

    Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name);

    if (!E) {
        ERR_EXPLAIN("Attempted to register method on non-existent class!");
        ERR_FAIL();
    }
//..
}

godotston errors. Godotston also fails with strange errors:

SCRIPT ERROR: GDScript::reload: Parse Error: Invalid export type. Only built-in and native resource types can be exported.
   At: res://XWaylandSurface.gd:3.
ERROR: reload: Method/Function Failed, returning: ERR_PARSE_ERROR
   At: modules/gdscript/gdscript.cpp:580.
ERROR: is_class_enabled: Condition ' !ti ' is true. returned: false
   At: core/class_db.cpp:1317.
Class is disabled for: 16
name: WlrXWayland
Running Wayland server on display godot-0
.
WaylandDisplay
WaylandDisplay/WlrBackend
WaylandDisplay/WlrBackend/WlrOutput
WaylandDisplay/WlrBackend/WlrCompositor
WaylandDisplay/WlrXdgShell
WaylandDisplay/WlrSeat
WaylandDisplay/WlrDataDeviceManager
WaylandDisplay/WlrKeyboard
ViewportBounds
ViewportBounds/Left
ViewportBounds/Right
ViewportBounds/Bottom
ERROR: get_node: Node not found: WaylandDisplay/WlrXWayland
   At: scene/main/node.cpp:1354.
SCRIPT ERROR: _ready: Attempt to call function 'start_xwayland' in base 'null instance' on a null instance.
   At: res://Main.gd:70.

though it doesn't seem the signal registering is broken like with Simula.

georgewsinger commented 4 years ago

Adding dummy signals to godot-haskell/template/demo/src/Lib.hs:

instance NativeScript Main where
  classInit base = Main base <$> newTVarIO 0
  classMethods =
    [ func NoRPC "_process" $
        \self [deltaVt] -> do
          delta <- fromGodotVariant deltaVt
          (sec, sec') <- atomically $ do
            t <- readTVar (_mTime self)
            let t' = t + delta
            writeTVar (_mTime self) t'
            return (floor t, floor t') :: STM (Int, Int)
          when (sec < sec') $
            "Seconds passed: " ++ Prelude.show sec'
              & T.pack
              & (toLowLevel :: Text -> IO GodotString)
              >>= Api.godot_print
    ]
  -- Dummy signals:
  classSignals = [ signal "map" [("gsvs", GodotVariantTypeObject)]
                 , signal "unmap" [("gsvs", GodotVariantTypeObject)]
                 ]

yields the same errors we're receiving in Simula:

OpenGL ES 3.0 Renderer: GeForce GTX 1070/PCIe/SSE2
Registering class Main
Registering method _process to class Main
ERROR: godot_nativescript_register_signal: Attempted to register method on non-existent class!
   At: modules/gdnative/nativescript/godot_nativescript.cpp:154.
Registering signal map to class Main
ERROR: godot_nativescript_register_signal: Attempted to register method on non-existent class!
   At: modules/gdnative/nativescript/godot_nativescript.cpp:154.
Registering signal unmap to class Main
Haskell NativeScript lib initialized
Seconds passed: 1
Seconds passed: 2

This suggests it's a signal registering bug in godot-haskell?

georgewsinger commented 4 years ago

:heavy_check_mark: Simula now uses Godot 3.1 with (i) a slightly modified fork of godot-haskell and (ii) many of the old godot-extra functions imported into Types.hs.