MathForGameDevelopers
MathForGameDevelopers copied to clipboard
Running on Mac
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?
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.
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.
Could you submit a patch please? It all works fine for me.
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);
}
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]