The program gets stuck at the glfwInit() function. However, there are no error messages and glfwInit() doesn't come to a stop. It's like the main thread is sleeping or run into an infinite loop. This problem seems not to be project-specific because I tried running a program that I hadn't changed in days where the same problem occurred (this program worked also fine). I am using Visual Studio 2019.
Here is the code of my main-function which should initiate GLFW:
int main() {
int width, height;
//Everything until this function will not execute and the program won't stop from its self.
if (!glfwInit()) {
std::cout << "ERROR::GLFW::Could not be initialized!" << std::endl;
}
setUpWindow();
GLFWwindow* window = createWindow(800, 800, "OpenGL Advanced");
if (window == nullptr) {
glfwTerminate();
return 2;
}
glfwMakeContextCurrent(window);
setUpListener(window);
bool gladIsLoaded = loadGlad();
if (!gladIsLoaded) {
glfwTerminate();
return 3;
}
setUpOpenGL();
startRenderLoop(&width, &height, window);
glfwTerminate();
return 1;
}
This is the call stack:
ntdll.dll!NtDeviceIoControlFile() Unknown
KernelBase.dll!DeviceIoControl() Unknown
kernel32.dll!DeviceIoControlImplementation() Unknown
hid.dll!00007ff86b631c2b() Unknown
hid.dll!00007ff86b631a1b() Unknown
dinput8.dll!00007ff83367492b() Unknown
dinput8.dll!00007ff833674648() Unknown
dinput8.dll!00007ff833674401() Unknown
dinput8.dll!00007ff833671f87() Unknown
dinput8.dll!00007ff83367424d() Unknown
dinput8.dll!00007ff833671037() Unknown
dinput8.dll!00007ff833678f1f() Unknown
dinput8.dll!00007ff8336790c6() Unknown
OpenglAdvanced.exe!_glfwInitJoysticksWin32() C
OpenglAdvanced.exe!_glfwPlatformInit() C
OpenglAdvanced.exe!glfwInit() C
OpenglAdvanced.exe!main() Line 48 C++
OpenglAdvanced.exe!invoke_main() Line 79 C++
OpenglAdvanced.exe!__scrt_common_main_seh() Line 288 C++
OpenglAdvanced.exe!__scrt_common_main() Line 331 C++
OpenglAdvanced.exe!mainCRTStartup() Line 17 C++
kernel32.dll!BaseThreadInitThunk() Unknown
ntdll.dll!RtlUserThreadStart() Unknown
I had the same issue, updating to the latest version (from 3.3.2 to 3.3.6) fixed the problem.
Related
I use GLAD (config) to load OpenGL functions and GLFW 3.3.8 to create context. Each time I start my program it pops a ERROR 1282 in glGetIntegerv from GLAD debug post-callback function (as far as I know it is invoked after each gl- function and prints an error if any occurred). I figured that this happens after returning from main().
Here's the code (it loads OpenGL 3.3 and shows red window until it is closed, pretty simple I think):
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main()
{
if(glfwInit() != GLFW_TRUE)
throw std::runtime_error{"Unable to initialize GLFW."};
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow * w{glfwCreateWindow(100, 100, "title", nullptr, nullptr)};
if(w == nullptr)
throw std::runtime_error{"Unable to create window."};
glfwMakeContextCurrent(w);
if(not gladLoadGLLoader(GLADloadproc(glfwGetProcAddress)))
throw std::runtime_error{"Unable to load OpenGL functions."};
glViewport(0, 0, 100, 100);
while(not glfwWindowShouldClose(w))
{
glfwPollEvents();
glClearColor(1.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(w);
}
glfwMakeContextCurrent(nullptr);
glfwDestroyWindow(w);
glfwTerminate();
std::cout << "Hey!" << std::endl;
return 0;
}
The output is:
Hey!
ERROR 1282 in glGetIntegerv
From this callstack:
#0 0x00416f91 in _post_call_callback_default_gl (name=0x446d40 <_glfwDataFormat+10036> "glGetIntegerv", funcptr=0x41c1ec <glad_debug_impl_glGetIntegerv#8>, len_args=2) at <glad.c>:45
#1 0x0041c265 in glad_debug_impl_glGetIntegerv#8 (arg0=33309, arg1=0x4526cc <num_exts_i>) at <glad.c>:1385
#2 0x00417168 in get_exts () at <glad.c>:220
#3 0x0042691f in find_extensionsGL () at <glad.c>:3742
#4 0x00426d12 in gladLoadGLLoader (load=0x402a2e <glfwGetProcAddress>) at <glad.c>:3821
#5 0x004016f8 in main () at <main.cpp>:33
Error 1282 is GL_INVALID_OPERATION, but it pops up after the program ended (or at least after the main() ended). Even if I separate the whole code in another function (i. e. create and destroy everything in separate function), and then invoke it in main(), the error still appears after the return 0; from main().
This did not happen when I used GLEW to load OpenGL functions, but maybe it was silenced. I didn't find anything similar to my problem on the internet. What am I doing wrong? Do I have to unload OpenGL or something like that?
UPD: Error message actually pops in gladLoadGLLoader(), not after the end of main().
The function glVertexAttribDivisor when used with CMake - it just throws the following error during compilation, which means that function is not imported.
error: 'glVertexAttribDivisor' was not declared in this scope; did you mean 'glVertexAttrib4iv'
I am currently using GLAD for loading openGL, like below:
if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) {
std::cout << "Failed to initialize OpenGL context" << std::endl;
return nullptr;
}
int gladInitRes = gladLoadGL();
if (!gladInitRes) {
fprintf(stderr, "Unable to initialize glad\n");
glfwDestroyWindow(window);
glfwTerminate();
return nullptr;
}
And printf("OpenGL version %i.%i\n", GLVersion.major, GLVersion.minor); prints out OpenGL version 4.2
I have recently been working with OpenGL and have decided to use C++ for my latest project with OpenGL. I am using xCode 8.1 with my library paths and header paths linked correctly. Everything compiles fine but i get this error at runtime:
2016-11-03 15:17:24.649264 Modulo[25303:14858638] [General] ERROR: Setting <GLFWContentView: 0x100343da0> as the first responder for window <GLFWWindow: 0x100222540>, but it is in a different window ((null))! This would eventually crash when the view is freed. The first responder will be set to nil.(
0 AppKit 0x00007fff85c069a4 -[NSWindow _validateFirstResponder:] + 566
1 AppKit 0x00007fff853f79eb -[NSWindow _setFirstResponder:] + 31
2 AppKit 0x00007fff8549f66a -[NSWindow _realMakeFirstResponder:] + 406
3 AppKit 0x00007fff8549f480 -[NSWindow makeFirstResponder:] + 123
4 libglfw3.3.dylib 0x000000010011194a _glfwPlatformCreateWindow + 610
5 libglfw3.3.dylib 0x000000010010d533 glfwCreateWindow + 428
6 Modulo 0x00000001000010a8 main + 296
7 libdyld.dylib 0x00007fff9c828255 start + 1
8 ??? 0x0000000000000001 0x0 + 1)
The code I run to generate this error is as follows:
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main(int argc, const char * argv[]) {
//Engine Startup.
std::cout << "<----- Engine Start-Up ----->" << std::endl;
//Initialize GLFW.
if(!glfwInit()) {
std::cout << "- GLFW Failed to Initialize!" << std::endl;
return -1;
}
std::cout << "+ GLFW Initialized!" << std::endl;
//Create GLFWWindow
GLFWwindow* window = glfwCreateWindow(640, 480, "Engine", nullptr, nullptr);
if(!window) {
std::cout << "- GLFWWindow Failed to Create!" << std::endl;
glfwTerminate();
return -1;
}
std::cout << "+ GLFWWindow Created!" << std::endl;
return 0;
}
The program performs as it should but this error could become an issue later and also makes the console hard to debug so I would like to try and sort it out early!
Thank you in advance and if any more information is needed please let me know! :)
I'm a beginner and I also faced this issue.
I got an error but succeed to create window. How about adding:
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
before glfwCreateWindow?
Note discussion here GLFW first responder error which indicates it is a known bug in macOS Sierra, which has been addressed in the git repo for GLFW, but not yet released.
I was troubleshooting an OpenGL application on a new computer when I discovered that GLFW could not create a window with the specified version of OpenGL. I created a minimal version of the application to test the version of OpenGL created, and no matter what version I hint, the version I get is 0.0. Do I simply not have OpenGL? This seems impossible, since glxgears runs and glxinfo suggests that I have version 2.1.
#include <iostream>
#include <GLFW/glfw3.h>
int main(int argc, const char *argv[]) {
if(!glfwInit()) {
return 1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
auto win = glfwCreateWindow(640, 480, "", NULL, NULL);
if(!win) {
return 1;
}
int major = 0, minor = 0;
glfwMakeContextCurrent(win);
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
std::cout << "Initialized with OpenGL "
<< major << "." << minor << std::endl;
glfwDestroyWindow(win);
glfwTerminate();
}
The output of the application is "Initialized with OpenGL 0.0". A window briefly opens and closes and the application terminates without errors.
The GL_MAJOR_VERSION and GL_MINOR_VERSION queries were introduced in GL 3.0. Prior to that, this will just generate an GL_INVALID_ENUM error during the glGetIntegerv call, and leave your variables untouched.
You have to use glGetString(GL_VERSION) to reliably get the verison number if you can't make sure that you are on a >= 3.0 context. If you need those as numbers, you'll have to manually parse the string.
I have just ported my C++ game to OS X and the first time it ran I get the following exception when trying to call SDL_SetVideoMode.
2012-09-28 15:01:05.437 SCRAsteroids[28595:707] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 259'
* First throw call stack:
(
0 CoreFoundation 0x00007fff8b53b716 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff90e30470 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8b53b4ec +[NSException raise:format:] + 204
3 AppKit 0x00007fff8a26a579 _NSCreateWindowWithOpaqueShape2 + 655
4 AppKit 0x00007fff8a268d70 -[NSWindow _commonAwake] + 2002
5 AppKit 0x00007fff8a2277e2 -[NSWindow _commonInitFrame:styleMask:backing:defer:] + 1763
6 AppKit 0x00007fff8a22692f -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1568
7 AppKit 0x00007fff8a2262ff -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
8 libSDL-1.2.0.dylib 0x0000000107c228f6 -[SDL_QuartzWindow initWithContentRect:styleMask:backing:defer:] + 294
9 libSDL-1.2.0.dylib 0x0000000107c20505 QZ_SetVideoMode + 2837
10 libSDL-1.2.0.dylib 0x0000000107c17af5 SDL_SetVideoMode + 917
11 SCRAsteroids 0x0000000107be60fb _ZN11SDLGraphics4initEP6IWorldii + 291
)
libc++abi.dylib: terminate called throwing an exception
Abort trap: 6
My init code looks like this:
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
return false;
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (!videoInfo) {
fprintf(stderr, "Video query failed: %s\n",
SDL_GetError());
return false;
}
/* the flags to pass to SDL_SetVideoMode */
videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */
/* This checks to see if surfaces can be stored in memory */
if (videoInfo->hw_available)
videoFlags |= SDL_HWSURFACE;
else
videoFlags |= SDL_SWSURFACE;
if (w == 0) {
widthViewport = videoInfo->current_w;
heightViewport = videoInfo->current_h;
cout << "Will use full screen resolution of ";
videoFlags |= SDL_FULLSCREEN;
} else {
cout << "Will use full user supplied resolution of ";
widthViewport = w;
heightViewport = h;
videoFlags |= SDL_RESIZABLE; /* Enable window resizing */
}
cout << widthViewport << "x" << heightViewport << "\n";
/* This checks if hardware blits can be done */
if (videoInfo->blit_hw)
videoFlags |= SDL_HWACCEL;
/* Sets up OpenGL double buffering */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
/* get a SDL surface */
surface = SDL_SetVideoMode(widthViewport, heightViewport,
SCREEN_BPP, videoFlags);
It gets into that last SDL call and throws the exception above. I have tried it in both full screen and resizable window mode, same thing.
I build my app old school, on the command line, as opposed to using Xcode.
SDL_main was yet again the culprit. My C++ main routine was in a file that does not include SDL.h, so it was not being redefined to SDL_main. The code that includes SDL is instead in a reusable static library, no main routine you see. I manually changed the name of my function to SDL_main and this means that SDL provides the essential main routine. I don't like doing this, but for the moment, on SDL 1.2.15 for Mac, it is necessary.
On Windows, the same new code causes linker conflicts. That's a new problem.
There are problems with calling the videocard in cocoa. So you need to initalize it before calling SDL_Setvideomode
Add the following method, and call it first in your main method
#include <dlfcn.h> //To make it work on mac
//This must be called before playing with SDL, else it won't work on osx.
void pre_init()
{
void* cocoa_lib;
cocoa_lib = dlopen( "/System/Library/Frameworks/Cocoa.framework/Cocoa", RTLD_LAZY );
void (*nsappload)(void);
nsappload = (void(*)()) dlsym( cocoa_lib, "NSApplicationLoad");
nsappload();
}
`
Same issue, but solved by linking libSDLmain (as well as libSDL). This in turn requires two frameworks: Foundation and Cocoa.
I didn't rename the main function.