FWGS / xash3d

DEPRECATED in favor of https://github.com/FWGS/xash3d-fwgs. Only bugfixes are accepted.
https://xash.su
GNU General Public License v3.0
551 stars 107 forks source link

MacOS crash in VGUI #350

Closed noodlecollie closed 6 years ago

noodlecollie commented 6 years ago

I've built Xash3D on Mac with the following CMake commands:

cmake -DSDL2_LIBRARIES=/my/path/to/SDL2/lib -DSDL2_INCLUDE_DIR=/my/path/to/SDL2/include -DHL_SDK_DIR=../hlsdk -DXASH_SDL=yes -DXASH_VGUI=yes -DXASH_X11=no -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32" -DCMAKE_EXE_LINKER_FLAGS="-m32" ../

When I run the engine with Half Life content, using vgui.dylib from the hlsdk/linux/release folder, I get the following crash:

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [0]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   vgui.dylib                      0x0bd44066 vgui::TextImage::getFont() + 22
1   vgui.dylib                      0x0bd445ec vgui::TextImage::getTextSize(int&, int&) + 44
2   vgui.dylib                      0x0bd43fc9 vgui::TextImage::setText(int, char const*) + 121
3   vgui.dylib                      0x0bd43d69 vgui::TextImage::TextImage(int, char const*) + 89
4   vgui.dylib                      0x0bd36c1e vgui::Label::Label(char const*) + 142
5   client.dylib                    0x0bc5e14d CVoiceStatus::Init(IVoiceStatusHelper*, vgui::Panel**) + 253
6   client.dylib                    0x0bc1f822 CHud::Init() + 1170
7   client.dylib                    0x0bc263ee HUD_Init + 30
8   libxash.dylib                   0x003e48c8 CL_LoadProgs + 1704
9   libxash.dylib                   0x003ef67d CL_Init + 413
10  libxash.dylib                   0x002f9795 Host_Main + 1941
11  xash3d                          0x0002be47 main + 151
12  libdyld.dylib                   0xa1539395 start + 1

Is this anything to do with the way I've built Xash? I can try without building with VGUI, but I'm not sure whether it's required by HL.

EDIT: I just tried building with -DXASH_VGUI=no and that didn't make a difference - running Half Life still requires vgui.dylib and still crashes in the same place.

mittorn commented 6 years ago

Check if vgui support library present

nekonomicon commented 6 years ago

Do you have vgui_support.dylib library? You can use vguiless hlsdk from hlsdk-xash3d repo.

noodlecollie commented 6 years ago

I have libvgui_support.so compiled in build/vgui_support, but not the .dylib.

EDIT: If I use the hlsdk-xash3d files, I get a segfault in a different place:

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [0]

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   ???                             0000000000 0 + 0
1   client.dylib                    0x0c3b3301 CBaseEntity::operator new(unsigned long, entvars_s*) + 65
2   hl.dylib                        0x0dc4cf07 CWorld* GetClassPtr<CWorld>(CWorld*) + 119
3   hl.dylib                        0x0dc4ce87 worldspawn + 23
4   libxash.dylib                   0x003bd038 SV_AllocPrivateData + 392
5   libxash.dylib                   0x003c7b32 SV_ParseEdict + 818
6   libxash.dylib                   0x003c833f SV_LoadFromFile + 415
7   libxash.dylib                   0x003c86ff SV_SpawnEntities + 655
8   libxash.dylib                   0x003cbfaa SV_LevelInit + 234
9   libxash.dylib                   0x003cd267 SV_NewGame + 343
10  libxash.dylib                   0x003204a4 Host_NewGame + 36
11  libxash.dylib                   0x003b2e5d SV_NewGame_f + 93
12  libxash.dylib                   0x002fa783 Cmd_ExecuteString + 1123
13  libxash.dylib                   0x002fa2cc Cbuf_Execute + 860
14  libxash.dylib                   0x004989ad Host_InputFrame + 333
15  libxash.dylib                   0x003207fc Host_Frame + 108
16  libxash.dylib                   0x00320756 Host_RunFrame + 246
17  libxash.dylib                   0x0032089f Host_FrameLoop + 95
18  libxash.dylib                   0x00323acb Host_Main + 2763
19  xash3d                          0x0002de47 main + 151
20  libdyld.dylib                   0xa1539395 start + 1

I haven't yet tried this with a -DXASH_VGUI=no build, though - unfortunately my lunch break has just run out.

a1batross commented 6 years ago

Ah. It's a known bug. Use code from "master" branch or just apply patch for vgui_support/CMakeLists.txt from https://github.com/FWGS/xash3d/commit/3b79ffd51fbd1dbbda7a0d43b3ddc581f86e8742#diff-db55c3ed1060b43c1b01475256e2cec6

15 февр. 2018 г. 4:55 ПП пользователь "Jonathan Poncelet" < notifications@github.com> написал:

I have libvgui_support.so compiled in build/vgui_support, but not the .dylib.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/FWGS/xash3d/issues/350#issuecomment-365933929, or mute the thread https://github.com/notifications/unsubscribe-auth/ADEJga3iiHCGezDnIZCFyoutum4swB_Hks5tVDdYgaJpZM4SGahP .

a1batross commented 6 years ago

And also set "-fvisibility=hidden" in compiler options. It's also fixed for "master" branch.

noodlecollie commented 6 years ago

Not to turn this into a general Mac support thread, but libxashmenu.dylib fails to link when compiling master, because Homebrew's libfontconfig.dylib isn't 32-bit.

Is there any general MacOS compiling information I should be reading up on?

a1batross commented 6 years ago

Don't use FreeType on OSX, it's not ready for it. (However you can try to compile your own freetype!)

You may use stbtt backend. It's enabled by default for all non-Win32 targets.

UPD: I was wrong. You need to enable it manually with "-DMAINUI_USE_STB=ON".

a1batross commented 6 years ago

There is only few macOS users and no developers using it. So macOS-related information and even engine support is very poor. :(

a1batross commented 6 years ago

Also you can refer to Travis CI buildscript. It's located in scripts/build_osx_engine.sh and scripts/travis_osx_deps.sh.

noodlecollie commented 6 years ago

That's been pretty helpful - however, I had to comment out typedef long off_t and typedef unsigned int uintptr_t in engine/common/soundlib/libmpg/mpg123.h because they were already defined by Xcode's headers.

Unfortunately I still couldn't get it to compile, because some of the SDL files reference Xlib.h and for some reason my install of XQuartz isn't visible to Make at that point. I don't think there's much else I can do tonight, but I'll keep trying tomorrow.

a1batross commented 6 years ago

SDL2 doesn't use Xlib, as far as I know. it completely relies on Cocoa functionality.

Do you have taken SDL2-ver.dmg from official site?

noodlecollie commented 6 years ago

I tried again today by first building the latest SDL2 from scratch and forcing it to build in 32-bit:

cmake -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32" -DCMAKE_OSX_ARCHITECTURES=i386 ..

Then I attempted to build Xash3D:

export CMAKE_PREFIX_PATH=/path/to/SDL2-2.0.7/build

# The extra X11 include path was just in case it was needed.
cmake -DCMAKE_C_FLAGS="-m32 -I/opt/X11/include" -DCMAKE_CXX_FLAGS="-m32
    -I/opt/X11/include" -DXASH_DOWNLOAD_DEPENDENCIES=yes -DXASH_SDL=yes
    -DXASH_VGUI=yes -DXASH_DLL_LOADER=no -DXASH_DEDICATED=no
    -DCMAKE_OSX_ARCHITECTURES=i386 -DMAINUI_USE_STB=yes
    -DXASH_VECTORIZE_SINCOS=yes -DSDL2_LIBRARY=/path/to/SDL2-2.0.7/build
    -DSDL2_INCLUDE_DIR=/path/to/SDL2-2.0.7/include ..

That went OK until I called make, when I got a linker error part way through:

Scanning dependencies of target xash3d
[ 36%] Building C object game_launch/CMakeFiles/xash3d.dir/xash.c.o
[ 36%] Linking C executable xash3d
Undefined symbols for architecture i386:
  "_SDL_ShowSimpleMessageBox", referenced from:
      _Xash_Error in xash.c.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [game_launch/xash3d] Error 1
make[1]: *** [game_launch/CMakeFiles/xash3d.dir/all] Error 2
make: *** [all] Error 2

I'm not quite sure why every time I try to build I get different errors. :P I have tried downloading SDL2 pre-built but the .framework file doesn't seem to be picked up when compiling.

a1batross commented 6 years ago

Just follow Travis CI buildscripts.

1) https://github.com/FWGS/xash3d/blob/master/scripts/travis_osx_deps.sh 2) https://github.com/FWGS/xash3d/blob/master/scripts/build_osx_engine.sh

First one installs SDL2 into appropriate directory. Second one builds engine and creates tarball.

Don't forget to clean build directory before starting! Just in case if there is cache error.

noodlecollie commented 6 years ago

I've made some progress! I can compile the entire engine now by seeing what the scripts do and performing those steps manually. However, I'm a bit stuck when it comes to running it. I'm at the stage where, after running make install, I get the pkg directory structure:

pkg/
  libSDL2-2.0.0.dylib - Copied from the SDL2 framework and renamed
  usr/
    local/
      bin/
        xash3d
      lib/
        xash3d/
          libvgui_support.dylib
          libxash.dylib
          libxashmenu.dylib
          vgui.dylib
          xash3d
          valve/
            ... HL content ...

I've set up DYLD_LIBRARY_PATH manually to include the pkg directory for SDL, the deepest xash3d directory for the Xash3D libraries, and also valve/dlls and valve/cl_dlls for the game libraries. When I run, I get the following error:

Sys_Warn: Could not load client library:
dlopen(valve/cl_dlls/client.dylib, 1): Library not loaded: /usr/local/lib/libSDL2-2.0.0.dylib
  Referenced from: /Users/vesper/Documents/afterburner/build/pkg/usr/local/lib/xash3d/valve/cl_dlls/client.dylib
  Reason: no suitable image found.  Did find:
    ../../../../libSDL2-2.0.0.dylib: code signature invalid for '../../../../libSDL2-2.0.0.dylib'

Failed to find library client.dylib
dlopen(client.dylib, 1): Library not loaded: /usr/local/lib/libSDL2-2.0.0.dylib
  Referenced from: /Users/vesper/Documents/afterburner/build/pkg/usr/local/lib/xash3d/valve/cl_dlls/client.dylib
  Reason: no suitable image found.  Did find:
    ../../../../libSDL2-2.0.0.dylib: code signature invalid for '../../../../libSDL2-2.0.0.dylib'

I'm guessing this is because the SDL2 lib is not actually 2.0.0, but rather 2.0.7 (because that's the one the dependency script referred to). Have I followed the steps correctly?

a1batross commented 6 years ago

Well, good. At least it compiles.

You need to place libSDL2 dylib into "lib" folder.

OR you can get rid of such file hierarchy and do it Windows-like, where all libraries and executables stays in one directory.

noodlecollie commented 6 years ago

I'll give it a try but I don't think that's quite the issue - it's finding the SDL2 dylib but saying "code signature invalid". This is the "SDL2" binary file from the SDL framework, that's copied and renamed to a dylib according to the build script.

FreeSlave commented 6 years ago

Signature is a security feature of macOS. Probably sdl2 package is not properly signed or new macOS version (newer than one on travis) somehow broke compatibility. You may try to sign it yourself.

Note if it's not important for you to build engine yourself, you may try out binary versions from https://github.com/FWGS/xash3d-deploy

noodlecollie commented 6 years ago

I'll close this because I haven't had build issues on Mac for a good while. I think the updates to the CMake scripts fixed my problems.