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

Running on Mac #3

Open
dboydor opened this issue Feb 2, 2016 · 5 comments
Open

Running on Mac #3

dboydor opened this issue Feb 2, 2016 · 5 comments

Comments

@dboydor
Copy link

dboydor commented Feb 2, 2016

I'm able to compile and run "master" like so:

make -f Makefile.osx
run_mfgd_osx

and I get:

6 iterations
3.148438

However, if I comment out this in main.c:

//return 0;

so it creates a game window, I get this:

./run_mfgd_osx: line 5: 23104 Segmentation fault: 11 ../mfgd

Is the game window runnable in on OS X?

@BSVino
Copy link
Owner

BSVino commented Feb 2, 2016

I'm working on that right now, actually. You can view my frustrations in second half of the latest stream. I should have it working by the next stream though.

@gemorin
Copy link
Contributor

gemorin commented Jun 12, 2016

This was still crashing for me on startup. It was asserting when getting the vecSunLight uniform location. It turns out that glfwInit() will change the current directory. That happens only on OS X (see http://www.glfw.org/docs/latest/group__init.html). This was breaking the shader loading: Renderer::LoadShaders() would find no shader (this could use some error checking).

The solution is to call getcwd() before glfwInit() and chdir back to the old dir. Once I made that change, the program seems to be working.

@BSVino
Copy link
Owner

BSVino commented Jun 24, 2016

Could you submit a patch please? It all works fine for me.

@gemorin
Copy link
Contributor

gemorin commented Jun 25, 2016

Here are my changes. I assume you'll want to move this in some platform specific file

Update: fixed formatting, referenced pull request #6

--- a/renderer/application.cpp
+++ b/renderer/application.cpp
@@ -23,6 +23,9 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON A
 #include <iostream>
 #include <fstream>
 #include <string.h>
+#ifdef __APPLE__
+#include <unistd.h>
+#endif

 #include <strutils.h>
 #include <common_platform.h>
@@ -50,8 +53,17 @@ CApplication::CApplication(int argc, char** argv)

 bool CApplication::OpenWindow(size_t iWidth, size_t iHeight, bool bFullscreen, bool bResizeable)
 {
-   if (!glfwInit())
-   {
+#ifdef __APPLE__
+   // On macOS, glfwInit() can change the current directory.
+   // See http://www.glfw.org/docs/latest/group__init.html
+   char *cwd = getcwd(0, 0);
+   int ret = glfwInit();
+   chdir(cwd);
+   free(cwd);
+#else
+   int ret = glfwInit();
+#endif
+   if (!ret) {
        printf("glfwInit failed\n");
        exit(1);
    }

@BSVino
Copy link
Owner

BSVino commented Jun 25, 2016

Github seems to have stripped a bunch of stuff out. If you're not comfortable submitting a pull request, do you want to just send the file to my email? [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants