Hopson97 / open-builder

Open "Minecraft-like" game with multiplayer support and Lua scripting support for the both client and server
https://github.com/Hopson97/open-builder/projects/3
GNU General Public License v3.0
700 stars 80 forks source link

Mac build and run instructions #134

Closed recursivetree closed 4 years ago

recursivetree commented 4 years ago

Currently, there are no build instructions for mac. Is it possible to use the linux/windows instructions? If yes, can you write it in the readme.md, or can you create a mac build instruction?

Hopson97 commented 4 years ago

I do not have a Mac nor have ever used one, so someone else would have to do this on my behalf.

(I believe you should be able to use cmake and make, not sure though)

grant-rez commented 4 years ago

I would like to work on this. I was able to compile by using brew (a common mac package manager) to install sfml then modifying the CMakeLists.txt. I did however encounter some problems when trying to run the code. The server seems to run fine (doesn't crash at least), but the client is crashing in multi-threaded code. Here are the 2 stack traces:

segfault thread:

__cxa_throw (@__cxa_throw:3)
nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parser::unexpect(nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::lexer::token_type) const (@nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parser::unexpect(nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::lexer::token_type) const:96)
nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parser::parse_internal(bool) (@nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parser::parse_internal(bool):35)
nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parser::parse() (@nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parser::parse():19)
nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer> nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parse<char const*, 0>(char const*, char const*, std::__1::function<bool (int, nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parse_event_t, nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>&)>) (@nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer> nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parse<char const*, 0>(char const*, char const*, std::__1::function<bool (int, nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>::parse_event_t, nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, unsigned long long, double, std::__1::allocator, nlohmann::adl_serializer>&)>):84)
FrameworkConfiguration::init() (@FrameworkConfiguration::init():94)
FrameworkConfiguration::create(applesauce::xpc::object) (@FrameworkConfiguration::create(applesauce::xpc::object):57)
CoreAnalytics::Client::handleConfigurationChange_sync(applesauce::xpc::dict const&) (@CoreAnalytics::Client::handleConfigurationChange_sync(applesauce::xpc::dict const&):53)
CoreAnalytics::Client::handleServerMessage_sync(applesauce::xpc::dict) (@CoreAnalytics::Client::handleServerMessage_sync(applesauce::xpc::dict):122)
___ZZN13CoreAnalytics6Client4initEvENK3$_1clEv_block_invoke (@___ZZN13CoreAnalytics6Client4initEvENK3$_1clEv_block_invoke:99)
_xpc_connection_call_event_handler (@_xpc_connection_call_event_handler:22)
_xpc_connection_mach_event (@_xpc_connection_mach_event:226)
_dispatch_client_callout4 (@_dispatch_client_callout4:8)
_dispatch_mach_msg_invoke (@_dispatch_mach_msg_invoke:107)
_dispatch_lane_serial_drain (@_dispatch_lane_serial_drain:69)
_dispatch_mach_invoke (@_dispatch_mach_invoke:131)
_dispatch_lane_serial_drain (@_dispatch_lane_serial_drain:69)
_dispatch_lane_invoke (@_dispatch_lane_invoke:101)
_dispatch_workloop_worker_thread (@_dispatch_workloop_worker_thread:138)
_pthread_wqthread (@_pthread_wqthread:68)
start_wqthread (@start_wqthread:8)

Main Thread Code:

getPreoptimizedClass (@getPreoptimizedClass:53)
getClassExceptSomeSwift(char const*) (@getClassExceptSomeSwift(char const*):9)
look_up_class (@look_up_class:24)
NSClassFromString (@NSClassFromString:56)
+[NSApplication initialize] (@+[NSApplication initialize]:66)
CALLING_SOME_+initialize_METHOD (@CALLING_SOME_+initialize_METHOD:7)
initializeNonMetaClass (@initializeNonMetaClass:167)
initializeNonMetaClass (@initializeNonMetaClass:27)
initializeAndMaybeRelock(objc_class*, objc_object*, mutex_tt<false>&, bool) (@initializeAndMaybeRelock(objc_class*, objc_object*, mutex_tt<false>&, bool):65)
lookUpImpOrForward (@lookUpImpOrForward:235)
_objc_msgSend_uncached (@_objc_msgSend_uncached:24)
sf::priv::WindowImplCocoa::setUpProcess() (@sf::priv::WindowImplCocoa::setUpProcess():19)
sf::priv::WindowImplCocoa::WindowImplCocoa(sf::VideoMode, sf::String const&, unsigned long, sf::ContextSettings const&) (@sf::priv::WindowImplCocoa::WindowImplCocoa(sf::VideoMode, sf::String const&, unsigned long, sf::ContextSettings const&):22)
sf::priv::WindowImpl::create(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&) (@sf::priv::WindowImpl::create(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&):26)
sf::Window::create(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&) (@sf::Window::create(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&):121)
Window::create(sf::VideoMode const&, unsigned int) (/Users/grantreszczyk/workspace/PERSONAL/open-builder/src/client/window.cpp:46)
Window::Window(ClientConfig const&) (/Users/grantreszczyk/workspace/PERSONAL/open-builder/src/client/window.cpp:22)
Window::Window(ClientConfig const&) (/Users/grantreszczyk/workspace/PERSONAL/open-builder/src/client/window.cpp:10)
runClientEngine(ClientConfig const&) (/Users/grantreszczyk/workspace/PERSONAL/open-builder/src/client/client_engine.cpp:54)
(anonymous namespace)::launchClient(ClientConfig const&, bool) (/Users/grantreszczyk/workspace/PERSONAL/open-builder/src/main.cpp:194)
Hopson97 commented 4 years ago

The seg fault thread is very strange, and nothing there appears to me be mine (Eg, I don't have nholman json)

In fact, the client code atm is entirely single threaded. The crash appears to be from creating the SFML window.

The only threading i do for now is the server and client run in a seperate threads for localhost play

grant-rez commented 4 years ago

I have been doing some more looking around and it looks that the graphics module does not play nice with macos.

"OpenGL versions above 3.0 are supported by SFML (as long as your graphics driver can handle them). Support for selecting the profile of 3.2+ contexts and whether the context debug flag is set was added in SFML 2.3. The forward compatibility flag is not supported. By default, SFML creates 3.2+ contexts using the compatibility profile because the graphics module makes use of legacy OpenGL functionality. If you intend on using the graphics module, make sure to create your context without the core profile setting or the graphics module will not function correctly. On OS X, SFML supports creating OpenGL 3.2+ contexts using the core profile only. If you want to use the graphics module on OS X, you are limited to using a legacy context which implies OpenGL version 2.1." https://www.sfml-dev.org/tutorials/2.5/window-opengl.php

recursivetree commented 4 years ago

Okay, then I think we won't ever by able to use this game on mac, because it uses opengl 3.0+ features.

Hopson97 commented 4 years ago

I am not using anything from the SFML graphics module for rendering, which is what the quote above is referring to.

" On OS X, SFML supports creating OpenGL 3.2+ contexts using the core profile only. If you want to use the graphics module on OS X, you are limited to using a legacy context which implies OpenGL version 2.1." "

Graphics module would be using things like SFML sf::RenderWindow to render primitive types such as sf::RectangleShape etc, of which I do not use any of

So there might still be hope here

grant-rez commented 4 years ago

I believe that you may use some things from the graphics module though as when I remove graphics from linking I get these errors:

[build] Undefined symbols for architecture x86_64:
[build]   "sf::Font::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
[build]       Font::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int) in libob-client.a(text.cpp.o)
[build]   "sf::Font::Font()", referenced from:
[build]       Font::Font() in libob-client.a(client.cpp.o)
[build]   "sf::Font::~Font()", referenced from:
[build]       Font::~Font() in libob-client.a(client_engine.cpp.o)
[build]       Font::Font() in libob-client.a(client.cpp.o)
[build]       Font::~Font() in libob-client.a(client.cpp.o)
[build]       Font::~Font() in libob-client.a(client_commands.cpp.o)
[build]   "sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)", referenced from:
[build]       gl::TextureArray::addTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]   "sf::Image::loadFromFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
[build]       (anonymous namespace)::bufferImage(unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       gl::loadRawImageFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       gl::TextureArray::addTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]   "sf::Image::create(unsigned int, unsigned int, unsigned char const*)", referenced from:
[build]       gl::Texture2d::create(unsigned int, unsigned int, unsigned char const*) in libob-client.a(textures.cpp.o)
[build]   "sf::Image::create(unsigned int, unsigned int, sf::Color const&)", referenced from:
[build]       gl::TextureArray::addTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]   "sf::Image::setPixel(unsigned int, unsigned int, sf::Color const&)", referenced from:
[build]       gl::TextureArray::addTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]   "sf::Image::Image()", referenced from:
[build]       (anonymous namespace)::bufferImage(unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       gl::Texture2d::create(unsigned int, unsigned int, unsigned char const*) in libob-client.a(textures.cpp.o)
[build]       gl::loadRawImageFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       gl::TextureArray::addTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       Client::Client(ClientConfig const&) in libob-client.a(client.cpp.o)
[build]   "sf::Image::~Image()", referenced from:
[build]       Client::~Client() in libob-client.a(client_engine.cpp.o)
[build]       (anonymous namespace)::bufferImage(unsigned int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       gl::Texture2d::create(unsigned int, unsigned int, unsigned char const*) in libob-client.a(textures.cpp.o)
[build]       gl::loadRawImageFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       gl::TextureArray::addTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       Client::Client(ClientConfig const&) in libob-client.a(client.cpp.o)
[build]       Client::init(ClientConfig const&, float) in libob-client.a(client.cpp.o)
[build]       ...
[build]   "sf::Font::getKerning(unsigned int, unsigned int, unsigned int) const", referenced from:
[build]       Font::getKerning(char, char) const in libob-client.a(text.cpp.o)
[build]   "sf::Font::getTexture(unsigned int) const", referenced from:
[build]       Font::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int) in libob-client.a(text.cpp.o)
[build]   "sf::Font::getLineSpacing(unsigned int) const", referenced from:
[build]       Font::getLineHeight() const in libob-client.a(text.cpp.o)
[build]   "sf::Font::getGlyph(unsigned int, unsigned int, bool, float) const", referenced from:
[build]       Font::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int) in libob-client.a(text.cpp.o)
[build]       Font::getGlyph(char) const in libob-client.a(text.cpp.o)
[build]   "sf::Image::getPixelsPtr() const", referenced from:
[build]       (anonymous namespace)::texImage2d(unsigned int, sf::Image const&) in libob-client.a(textures.cpp.o)
[build]       gl::Texture2d::create(unsigned int, unsigned int, unsigned char const*) in libob-client.a(textures.cpp.o)
[build]       gl::TextureArray::addTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libob-client.a(textures.cpp.o)
[build]       Client::sendPlayerSkin(sf::Image const&) in libob-client.a(client_commands.cpp.o)
[build]   "sf::Image::getSize() const", referenced from:
[build]       (anonymous namespace)::texImage2d(unsigned int, sf::Image const&) in libob-client.a(textures.cpp.o)
[build]       gl::Texture2d::create(unsigned int, unsigned int, unsigned char const*) in libob-client.a(textures.cpp.o)
[build]       Client::sendPlayerSkin(sf::Image const&) in libob-client.a(client_commands.cpp.o)
[build]       Font::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int) in libob-client.a(text.cpp.o)
[build]   "sf::Texture::copyToImage() const", referenced from:
[build]       Font::init(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int) in libob-client.a(text.cpp.o)
[build] ld: symbol(s) not found for architecture x86_64

Also, I tried to build SFML from scratch and the crashing persisted.

Hopson97 commented 4 years ago

I use things from it, but not for rendering, which is what the quote referring to.

grant-rez commented 4 years ago

I see. I made a thread on the SFML forum asking for some help, hopefully that will be fruitful. Also, I was able to compile and run the minimal example provided by SFML of using it with OpenGL (https://www.sfml-dev.org/tutorials/2.5/window-opengl.php), so I am at a bit of a loss as to what is going on.

Hopson97 commented 4 years ago

Apparently this may be caused by the OpenGL debugging code here:

https://github.com/Hopson97/open-builder/blob/master/src/client/gl/gl_errors.cpp#L80

The body of this function could be wrapped in a

#ifndef MAC (or whatever)

...

#endif 

and it could fix the issue.

Hopson97 commented 4 years ago

150

Solved?

recursivetree commented 4 years ago

Just tested it, build and run works, however the mouse input isn't working correctly, but this isn^t part of this issue.

grant-rez commented 4 years ago

Hmmm, try replacing line 151 in client.cpp with #if 1 and then compile. The fix that I made for my mouse to work seemed a bit odd, but it worked for my computer.