Fix mingw build, fix dangling pointer

Still doesn't work on windows, because of GL errors.