SDL quite event handler with two windows

Hello everyone,
I am new in SDL. I have one question that when I use two windows ( e.g. s2 in the blow code) the quite event handler become does not function ( does not trigger). If I have one window everything works fine. Is it a bug in SDL?

thanks
You can make the quite even handler works if you remove one of the windoes in the below code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<Windows.h>
#include <SDL.h>
#include <glew.h>
#include <iostream>

int main(int argc,char** argv) {
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_Window *s1 = nullptr;
	SDL_Window *s2 = nullptr;
	s1 = SDL_CreateWindow("Hello word",800,300,500,300,SDL_WINDOW_OPENGL);
	s2 = SDL_CreateWindow("Hello word2", 10, 10, 500, 300, SDL_WINDOW_OPENGL);
	SDL_Event myEvent;
	while (1) {

		while (SDL_PollEvent(&myEvent)) {
			switch (myEvent.type) {
			case SDL_QUIT:
				std::cout << "Quit" << std::endl;
				return 0;
				break;
			case SDL_MOUSEMOTION:
				std::cout << " x: " << myEvent.motion.x << " y: " << myEvent.motion.y << std::endl;
				break;
			}

		}
	}

	return 0;
}
Last edited on
A SDL_QUIT event should be generated when the last window is closed.

If you want to handle individual windows being closed you should check for the SDL_WINDOWEVENT/SDL_WINDOWEVENT_CLOSE event.

https://wiki.libsdl.org/SDL_WindowEvent
Topic archived. No new replies allowed.