I have made a very basic SDL application which kept going for a few iterations of the main loop, but then crashed. I have located the error to lie in SDL_GL_SwapWindow, which works the first two times, then crashes. This is a very simplified version that I have actually tried and it did the same thing.
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* SDLWindow = SDL_CreateWindow("Balls", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
SDL_GLContext SDLGLContext = SDL_GL_CreateContext(SDLWindow);
glewInit();
glViewport(0, 0, 800, 600);
SDL_GL_SwapWindow(SDLWindow);
SDL_GL_SwapWindow(SDLWindow);
SDL_GL_SwapWindow(SDLWindow); //crashes here
return 0;
First two calls work just fine, the third one crashes the program. Strangely, the crash occured in igd10umd32.dll and the debugger didn't allow me to read that file. I looked that up on the internet, but no attempts to fix the library worked. Besides, if the problem was in this library, it probably wouldn't appear under such strange conditions.
And what's even weirder is that the program works fine on my second laptop. And when I compiled it there and ran it on this laptop, it also worked fine.
I'm using Windows 10. I've worked with SDL/OpenGL many times and never encountered anything like this. Any ideas what may cause this very chaotic behavior?
Solved. It was nothing more than an NVIDIA bug. Updating the driver got rid of all problems.
Related
When using the following BGFX code:
#include "GLFW/glfw3.h"
#include <bgfx/bgfx.h>
int main() {
glfwInit();
GLFWwindow* window = glfwCreateWindow(800, 600, "Hello, bgfx!", NULL, NULL);
bgfx::Init bgfxInit;
bgfxInit.type = bgfx::RendererType::Count; // Automatically choose a renderer.
bgfxInit.resolution.width = 800;
bgfxInit.resolution.height = 600;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
bgfx::init(bgfxInit);
}
A black openGL window pops up and appears fine for a second, however, a GLXBadDrawable error then pops up. I do not know what the cause of this error is, and the other question has no answers and has not been active for some time now.
I believe that this is not an issue with the code, but rather my machine, however, I may be wrong.
I currently have a Lenovo T400 laptop, with a Core 2 Duo P9500. I have 2 built-in GPUs, a Mobile 4 Series Chipset integrated graphics chip, along with an ATI Mobility Radeon HD 3450/3470. I am also running Artix Linux with the 6.0.7-artix1-1 kernel. I also am using the glfw-x11 and glfw packages if that helps, along with the i3-gaps window manager.
I have also attempted to use SDL2 instead of GLFW, and the same issue occurs. However, for GLFW a black window shows up, while in SDL2, a transparent(?) window instead shows up. Searching the github issues page also yielded no results.
I've got a weird problem that's suddenly appeared across all projects I'm working on. I'm using C++, SDL2 and OpenGL, and one of the first things that happens in my int main is to create an SDL window with an OpenGL flag like below:
int main( int argc, char* args[] )
{
//Minor stuff here e.g. initialising SDL
mainwindow = SDL_CreateWindow("...", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL);
}
For some reason this has started to cause a segmentation fault. If I change the flag from SDL_WINDOW_OPENGL to anything else, it does create a window but obviously fails shortly afterwards given the lack of an OpenGL context to do anything with. I've gone as far as to strip out all code except for the SDL and OpenGL initialisation stuff, and it still fails with a segfault error.
This issue has started as of today across two projects that share the same basic int main structure. This leads me to believe it's not a code issue (largely because the code hasn't actually changed), but that something with my setup / environment has gone wrong. So far I've tried the following to no avail:
Redownloaded latest SDL library
Redownloaded latest GLEW library
Reinstalled Codeblocks
Any ideas for a) what might be causing this and b) where I should start looking to fix it?
Thanks
Nathan
And like so many other problems in life, the answer turned out to be drivers. A system-wide update of some kind interfered with the graphics' ability to render any kind of OpenGL. A direct download and install of the latest graphic drivers fixed it.
I've just started to testing SDL library. I've notice that SDL_CreateWindow() is very slow when I set SDL_WINDOW_OPENGL flag (takes about 10x longer). And I'm talking only about the window creation, not creation of OpenGl context.
Basically this line takes about 55 ms on my machine:
SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
And this takes about 500 ms:
SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL);
And I feel this is much faster today. Yesterday I't feelt like it took about 2s to show the window (though I didn't measure it)
Is this normal to take so long or am I missing something? I'm also new to OpenGL so I can't even guess what it is doing under the hood.
The thing that takes a long time is loading the OpenGL driver from your graphics card vendor.
I was having a similar issue, so I rebuild SDL with symbols and profiled it. Almost all the time was spent in the ChoosePixelFormat function, which is part of wgl, the windows specific opengl interface. For me, today, with an Nvidia card, it takes a whole second to do this initialization.
There is a nice thread here that describes the issues in more detail:
https://hero.handmade.network/forums/code-discussion/t/2503-%5Bday_235%5D_opengls_pixel_format_takes_a_long_time
My program starts with a loading window while it is compiling shaders, loading textures etc. I then want to be able to launch a fullscreen application and use these resources. My understanding is that the openGL context must be the same before and after. I tried two methods for this: first of all I tried making a second window which was fullscreen, and used the SDL_GL_makecurrent command on this window to 'transfer' the context across (couldn't find where I read about this method), and secondly tried just fullscreening the loading window. Both of these methods resulted in the loading screen being moved to the top left corner of the screen. However opengl commands no longer ran properly in fullscreen, including clearing buffers which meant that the window contained the contents of my desktop/background applications.
Is there a proper way of doing this? Or is this a strange bug in sdl/opengl drivers?
Code to fullscreen original window:
//opengl commands work fine up to here
//now to fullscreen
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_SetWindowSize(window, 1366, 768); //tried this on either side of line above and without either line
glViewport(0, 0, 1366, 768); //update viewport
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);
//window should be whited, other draw commands tried and all fail or distort
SDL_GL_SwapWindow(window);
Creating a new window and using previous context:
//Fine up to here
window2 = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1366, 768, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_SHOWN);
SDL_GL_MakeCurrent(window2, glContext); //created with SDL_GL_CreateContext(oldwindow);
//draw commands dont work
PS: running ubuntu
Update: In the second code, reusing the context in a new window, it returns an error saying 'invalid window' when it fails, which is most of the time but not always. When it fails, the screen ends up completely corrupted(black with weird white squares and patterns), ending the program will not clear the screen of this (although screenshots are perfectly fine?), but it can be restored by ctrl+f1 to terminal then ctrl+f7 back
I dont really know if its a bug. I experienced the same issue with sdl2 and opengl.
Create an regular window
attach to opengl context.
fullscreen
BOOM. black screen and crashed window.
I only noticed that issue in ubuntu.
Trought some tests i found a quick way to fix it:
Uint32 flags = 0;
flags |= SDL_WINDOW_RESIZABLE;
//bla bla bla your tags
flags |= SDL_WINDOW_OPENGL;
m_window = SDL_CreateWindow( "hello gl", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_screen.x, m_screen.y,flags);
m_glContext = SDL_GL_CreateContext(m_window);
//Set right the way the screen to fullscrene false
SDL_SetWindowFullscreen(m_window, SDL_FALSE);
Now the fullscreen seems to work without problem.
any idea why the following code isn't working? Nothing happens when it's called, the window title is still untitled. I'm on Ubuntu linux.
SDL_Init( SDL_INIT_VIDEO );
SDL_WM_SetCaption("Window Title", "Icon Title");
SDL_Surface* screen = SDL_SetVideoMode( 512, 512, 32, SDL_HWSURFACE | SDL_DOUBLEBUF );
Vector2 center = Vector2(256,256);
const char* c = "test";
SDL_WM_SetCaption( c, 0 );
SDL_Event event;
Make your first call to SDL_WM_SetCaption after SDL_SetVideoMode has been called. Also, remove the second test call. If you are using SDL 1.3, (it sounds like you are using 1.2, so you can probably ignore this), call SDL_SetWindowTitle:
Your code may not be at fault. Ubuntu may be responsible for that one. Or rather, the window manager/compositor Compiz that it uses:
https://bugs.launchpad.net/ubuntu/+source/compiz/+bug/257391
Switching from Compiz to Metacity could help you figure out if you are affected by this bug as well.
There may be something else going on: I don't get a title when I call SetCaption after SetVideoMode but I do get one when I set the caption before, which is not the behavior you are observing.