I learning SDL2 . I am trying create two processes which will render a window using fork function.The program compiles fine but it doesn't execute. When I try to execute I get folloing error:-
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
after 262 requests (261 known processed) with 36 events remaining.
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
after 260 requests (260 known processed) with 35 events remaining.
I really have no idea what are these errors ? I don't event know that are these Linux related errors or Programming related errors.
here is my program :-
#include <iostream>
#include <SDL2/SDL.h>
#include <thread>
#include <unistd.h>
using namespace std;
void th(SDL_Window* win,SDL_Surface *win_sur)
{
int i=0,o=0,p=0;
SDL_Event e;
while(1)
{
while(SDL_PollEvent(&e))
{
if(e.type == SDL_QUIT)
goto end;
}
SDL_FillRect(win_sur,0,SDL_MapRGB(win_sur->format,i,o,p));
SDL_UpdateWindowSurface(win);
i++;o+=2;p+=3;
SDL_Delay(10);
}
end:
;
}
int main()
{
SDL_Window *win,*win2;
SDL_Init(SDL_INIT_VIDEO);
win = SDL_CreateWindow("win",10,100,500,500,SDL_WINDOW_OPENGL);
SDL_ShowWindow(win);
SDL_Surface *win_sur = SDL_GetWindowSurface(win);
win2 = SDL_CreateWindow("win2",10,500,500,500,SDL_WINDOW_OPENGL);
SDL_ShowWindow(win2);
SDL_Surface *win_sur2 = SDL_GetWindowSurface(win);
int i=0,o=0,p=0;
SDL_FillRect(win_sur,0,SDL_MapRGB(win_sur->format,i,o,p));
SDL_UpdateWindowSurface(win);
SDL_FillRect(win_sur2,0,SDL_MapRGB(win_sur2->format,i,o,p));
SDL_UpdateWindowSurface(win2);
pid_t pid = fork();
if(!pid)
th(win2,win_sur2);
else if(pid>0)
th(win,win_sur);
else
printf("Error");
SDL_DestroyWindow(win);
SDL_Quit();
}