Using SDL_UpdateWindowSurface in sound callback

The following code uses SDL_UpdateWindowSurface in the sound callback, prints the error, then uses SDL_UpdateWindowSurface in the main thread.
It prints “Unable to make EGL context current (call to eglMakeCurrent failed, reporting an error of EGL_BAD_ACCESS”:

#include <stdint.h>
#include <SDL2/SDL.h>

const int samplerate = 48000;
const int sampleframe = 800;

void SoundCallback(void* udata, Uint8 *stream, int len);
SDL_Window *window;
SDL_Surface *screenSurface;

int pos = 0;

//Raw 6*14 bitmap font (reduced to ASCII for demonstration purposes)

const uint32_t rawfont[] = {0xFFFFFFFF,0x5F7C0000,0xF6DF6D76,0x0000007D,0x00000020,0x00000000,0x00000000,0x00000000,0x00000021,0x04100000,0x40041041,0x00000000,0x00000022,0x0A28A000,0x00000000,0x00000000,0x00000023,0xCA280000,0xA29F28A7,0x00000000,0x00000024,0x45784000,0xF5143061,0x00000010,0x00000025,0x95480000,0x954A1042,0x00000000,0x00000026,0x49180000,0x62495462,0x00000001,0x00000027,0x04104000,0x00000000,0x00000000,0x00000028,0x82108000,0x20820820,0x00000810,0x00000029,0x08102000,0x82082082,0x00000210,0x0000002A,0x4E544000,0x00000045,0x00000000,0x0000002B,0x00000000,0x01047C41,0x00000000,0x0000002C,0x00000000,0x40000000,0x00000210,0x0000002D,0x00000000,0x00007800,0x00000000,0x0000002E,0x00000000,0x40000000,0x00000000
,0x0000002F,0x08410000,0x10821042,0x00000004,0x00000030,0x51380000,0xE4535556,0x00000000,0x00000031,0x07100000,0xF1041041,0x00000001,0x00000032,0x11380000,0xF0421084,0x00000001,0x00000033,0x103C0000,0xF41040E4,0x00000000,0x00000034,0x8C200000,0x821F24A2,0x00000000,0x00000035,0x417C0000,0xF41040F0,0x00000000,0x00000036,0x42700000,0xE45144F0,0x00000000,0x00000037,0x107C0000,0x20841082,0x00000000,0x00000038,0x51380000,0xE45128E4,0x00000000,0x00000039,0x51380000,0x72107914,0x00000000,0x0000003A,0x00000000,0x40000001,0x00000000,0x0000003B,0x00000000,0x40000001,0x00000210,0x0000003C,0x00000000,0x06060466,0x00000000,0x0000003D,0xC0000000,0x001F0007,0x00000000,0x0000003E,0xC0000000,0x00CC40C0,0x00000000
,0x0000003F,0x10380000,0x40043104,0x00000000,0x00000040,0x51380000,0xE04D6DB5,0x00000001,0x00000041,0x84100000,0x145F44A2,0x00000001,0x00000042,0x513C0000,0xF45144F4,0x00000000,0x00000043,0x42700000,0xC0810410,0x00000001,0x00000044,0x491C0000,0x72514514,0x00000000,0x00000045,0x417C0000,0xF04105F0,0x00000001,0x00000046,0x417C0000,0x104105F0,0x00000000,0x00000047,0x42700000,0xC49145D0,0x00000001,0x00000048,0x51440000,0x145145F4,0x00000001,0x00000049,0x047C0000,0xF1041041,0x00000001,0x0000004A,0x083C0000,0x72082082,0x00000000,0x0000004B,0x49440000,0x12450C31,0x00000001,0x0000004C,0x41040000,0xF0410410,0x00000001,0x0000004D,0x4A280000,0x14515555,0x00000001,0x0000004E,0xD3440000,0x16595554,0x00000001
,0x0000004F,0x51380000,0xE4514514,0x00000000,0x00000050,0x513C0000,0x10413D14,0x00000000,0x00000051,0x51380000,0xE4514514,0x00001810,0x00000052,0x513C0000,0x144914F4,0x00000001,0x00000053,0x41780000,0xF4102060,0x00000000,0x00000054,0x047C0000,0x41041041,0x00000000,0x00000055,0x51440000,0xE4514514,0x00000000,0x00000056,0x51440000,0x410A28A4,0x00000000,0x00000057,0x51440000,0xA2955554,0x00000000,0x00000058,0x91440000,0x144A1042,0x00000001,0x00000059,0x91440000,0x410410A2,0x00000000,0x0000005A,0x107C0000,0xF0421042,0x00000001,0x0000005B,0x8208E000,0x20820820,0x00000E08,0x0000005C,0x82041000,0x02081040,0x00000041,0x0000005D,0x0820E000,0x82082082,0x00000E20,0x0000005E,0x4A100000,0x00000004,0x00000000
,0x0000005F,0x00000000,0x00000000,0x00003F00,0x00000060,0x00206000,0x00000000,0x00000000,0x00000061,0xC0000000,0x66517903,0x00000001,0x00000062,0x41041000,0xF4514533,0x00000000,0x00000063,0x80000000,0xE0410417,0x00000001,0x00000064,0x90410000,0x66514517,0x00000001,0x00000065,0x80000000,0xE0417D13,0x00000001,0x00000066,0xC209C000,0x20820827,0x00000000,0x00000067,0x80000000,0xE0462497,0x00039144,0x00000068,0x41041000,0x14514533,0x00000001,0x00000069,0xC0004000,0xF1041041,0x00000001,0x0000006A,0xC0008000,0x82082083,0x0001C820,0x0000006B,0x41041000,0x12450C52,0x00000001,0x0000006C,0x04107000,0xF1041041,0x00000001,0x0000006D,0xC0000000,0x55555552,0x00000001,0x0000006E,0x40000000,0x14514533,0x00000001
,0x0000006F,0x80000000,0xE4514513,0x00000000,0x00000070,0x40000000,0xF4514533,0x00004104,0x00000071,0x80000000,0x66514517,0x00041041,0x00000072,0x40000000,0x10410533,0x00000000,0x00000073,0x80000000,0xF4081817,0x00000000,0x00000074,0xC2080000,0xC0820827,0x00000001,0x00000075,0x40000000,0x66514514,0x00000001,0x00000076,0x40000000,0x410A2914,0x00000000,0x00000077,0x40000000,0xA2955554,0x00000000,0x00000078,0x40000000,0x128410A4,0x00000001,0x00000079,0x40000000,0x428A2914,0x0000C410,0x0000007A,0xC0000000,0xF0841087,0x00000001,0x0000007B,0x04118000,0x41040C41,0x00001810,0x0000007C,0x04104000,0x41041041,0x00000410,0x0000007D,0x04103000,0x41046041,0x00000310,0x0000007E,0x09552000,0x00000000,0x00000000,};

int main(int argc, char *argv[]){
	SDL_Init(SDL_INIT_EVERYTHING);
	window = SDL_CreateWindow("Using SDL_UpdateWindowSurface in sound callback", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
	screenSurface = SDL_GetWindowSurface(window);
    SDL_AudioSpec sdlaudiospec;
    // Set the audio format
    sdlaudiospec.freq = samplerate;
    sdlaudiospec.format = AUDIO_S16SYS;
    sdlaudiospec.channels = 1;    	/* 1 = mono, 2 = stereo */
    sdlaudiospec.samples = sampleframe;  	/* Good low-latency value for callback */
    sdlaudiospec.callback = SoundCallback;
    //sdlaudiospec.userdata = sortview;
	SDL_OpenAudio(&sdlaudiospec, NULL);
	SDL_Init(SDL_INIT_AUDIO);
    SDL_PauseAudio(0);
	while(!pos);
	SDL_UpdateWindowSurface(window);
	while(1);
    return 0;
}

/// sound generator callback run by SDL
void SoundCallback(void* udata, Uint8 *stream, int len)
{
    int16_t* data = (int16_t*)stream;
    size_t size = len / sizeof(int16_t);

        for (size_t i = 0; i < size; ++i){
			data[i] = 0;
    	}
    	SDL_UpdateWindowSurface(window);
		uint32_t* bitmapdata = (uint32_t*)screenSurface->pixels;
		int width; int height; SDL_GetWindowSize(window, &width, &height);
		const char* a = SDL_GetError();
		for(int i=0; a[i]; i++){
			uint16_t character = a[i];
			size_t glyph;
			{
				size_t min = 1;
				size_t max = sizeof rawfont/sizeof (uint32_t)/4;
				while(max-min>1){
					if(rawfont[(min+max)/2*4]>character) max=(min+max)/2; else min=(min+max)/2;
				}
				if(rawfont[min*4]==character) glyph=min; else glyph=0;
			}
			for(int q=0; q<84; q++){
				bool pixel = (rawfont[glyph*4+1+q/32]>>(q%32))&1;
				size_t w = i*6+q%6+(q/6+14)*width;
				bitmapdata[w] = pixel ? 0xFFFFFF : 0x000000;//(bitmapdata[w]>>1)&0x7F7F7F;
			}
		}
	pos++;
	SDL_PauseAudio(1);
}

The reason I would like to use SDL_UpdateWindowSurface in sound callback is because I keep all frame-perfect timing synchronised to the sound callback. So every frame, the image is drawn, 800 samples are played, and 1÷60 seconds pass.