SDL2 Porting bug, strange window

Hello!
I’m porting libSDL2 to OpenVMS, need some help.
I successfully build the library,
trying test below, its simple rectangle,
but get a window looks like https://vaxvms.org/libsdl2_problem.jpg
Can anybody guru have any idea what’s it may be the problem ?
I retrospect to old 2.0.3 version, and see no problem, window looks nice. 2.0.8 still has the problem.
Please, I’m waiting any ideas.

#include <SDL2/SDL.h>

const int SDL_SCREEN_WIDTH = 640;
const int SDL_SCREEN_HEIGHT = 480;

int main (int argc, char ** args) {

int i;

if( SDL_Init( SDL_INIT_VIDEO ) != 0 )
{
printf(“Error SDL_Init\n”);
return 1;
}

SDL_Surface* screen_surface = NULL;
SDL_Window* window = NULL;

window = SDL_CreateWindow(“Hello, SDL 2!”,SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SDL_SCREEN_WIDTH, SDL_SCREEN_HEIGHT,
SDL_WINDOW_SHOWN);

if (window == NULL) {
    printf("Error SDL_CreateWindow\n");
    return 1;
}

screen_surface = SDL_GetWindowSurface(window);
SDL_FillRect(screen_surface, NULL, SDL_MapRGB(screen_surface->format, 255, 0255, 0255));
SDL_UpdateWindowSurface(window);

scanf("%d",&i);

SDL_Delay(2000);

}

I don’t see anything wrong with the code (except that 0255 is an octal literal so it’s really the value 173).

SDL 2.0.8 is pretty old (from 2018). You might want to try using a newer version and see if that works better.

Have you tried rendering inside a loop to rule out that it’s not just some glitch that’s happening the first time?

Side note: SDL seems to have issues with scanf(), it actually was causing the program on my computer (Ubuntu linux) to freeze, so I swapped out scanf and printf for SDL_Log().

As for the window issue, my guess is that your program is trying to draw that rectangle and update the screen before the window is fully initialized.
SDL will emit several events when the window is ready, so we can use that as a time to redraw the rectangle.

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

const int SDL_SCREEN_WIDTH = 640;
const int SDL_SCREEN_HEIGHT = 480;

int main (int argc, char ** args) {

	int i;

	if( SDL_Init( SDL_INIT_VIDEO ) != 0 )
	{
		SDL_Log("Error SDL_Init\n");
		return 1;
	}

	SDL_Surface* screen_surface = NULL;
	SDL_Window* window = NULL;

	window = SDL_CreateWindow("Hello, SDL 2!",SDL_WINDOWPOS_UNDEFINED,
	SDL_WINDOWPOS_UNDEFINED, SDL_SCREEN_WIDTH, SDL_SCREEN_HEIGHT,
	SDL_WINDOW_SHOWN);
	
	if (window == NULL) {
	    SDL_Log("Error SDL_CreateWindow\n");
	    return 1;
	}

	screen_surface = SDL_GetWindowSurface(window);
	SDL_FillRect(screen_surface, NULL, SDL_MapRGB(screen_surface->format, 255, 0255, 0255));
	// I suspect the OS is still setting up your window at this point in time.
	SDL_UpdateWindowSurface(window);

	bool run = true;
	while(run) {
		SDL_Event ev;
		while(SDL_PollEvent(&ev)) {
			switch(ev.type) {
				case SDL_WINDOWEVENT:
					// If this code runs as expected, then for the next step,
					// try commenting out this SDL_FillRect line, you might just 
					// need the call to SDL_UpdateWindowSurface after providing a delay.
					SDL_FillRect(screen_surface, NULL, SDL_MapRGB(screen_surface->format, 255, 0255, 0255));
					break;
	
				case SDL_QUIT:
					run = false;
					break;
			}
		}
		SDL_UpdateWindowSurface(window);

		// trying for about 33 frames per second (1000/30)
		SDL_Delay(30);
	}
	SDL_Quit();
	SDL_Log("%d", i);
}

P.S.
Are you really running this on a VAX, or is just a virtual machine?

Thank you for replay,
code isnt wrong, bug is in the my libSDL port to OpenVMS. I hope SDL hackers look to the image and get any idea in head, what it may be, what does it look like.
If I link this example code with SDL 2.0.3 I ported in 2015 year, all things work correct, I see color rectangle. My first idea was a problem with bug little/big endian detect, but little endian processor seems to detected correctly, then I look into SDL_memset function, it seems not bug here too…

This is Alpha, little-endian processor

Unfortunately, the same

Did it actually freeze or was it just wait for you to input something in the terminal?

Waiting for an input in the console is poison for every GUI program. Everything freezes as if the program is taking a break.

Darn it, I thought scanf was another printing function. Yeah, the program was just paused for input.
I’ll put my “bad C++ programmer dunce cap” back on.

So a basic game-loop did not fix the issue. Now what? Perhaps double check that the screen_surface is not NULL?

Edit: this is a quote from SDL_GetWindowSurface remarks → “This surface will be invalidated if the window is resized. After resizing a window this function must be called again to return a valid surface.”

So maybe in the SDL_WINDOWEVENT case we should also be requesting the new surface with SDL_GetWindowSurface()?

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

const int SDL_SCREEN_WIDTH = 640;
const int SDL_SCREEN_HEIGHT = 480;

int main (int argc, char ** args) {

	int i;

	if( SDL_Init( SDL_INIT_VIDEO ) != 0 )
	{
		SDL_Log("Error SDL_Init\n");
		return 1;
	}

	SDL_Surface* screen_surface = NULL;
	SDL_Window* window = NULL;

	window = SDL_CreateWindow("Hello, SDL 2!",SDL_WINDOWPOS_UNDEFINED,
	SDL_WINDOWPOS_UNDEFINED, SDL_SCREEN_WIDTH, SDL_SCREEN_HEIGHT,
	SDL_WINDOW_SHOWN);
	
	if (window == NULL) {
	    SDL_Log("Error SDL_CreateWindow\n");
	    return 1;
	}

	screen_surface = SDL_GetWindowSurface(window);
	SDL_FillRect(screen_surface, NULL, SDL_MapRGB(screen_surface->format, 255, 255, 255));
	// I suspect the OS is still setting up your window at this point in time.
	SDL_UpdateWindowSurface(window);

	bool run = true;
	while(run) {
		SDL_Event ev;
		while(SDL_PollEvent(&ev)) {
			switch(ev.type) {
				case SDL_WINDOWEVENT:	
					screen_surface = SDL_GetWindowSurface(window);
					SDL_FillRect(screen_surface, NULL, SDL_MapRGB(screen_surface->format, 255, 255, 255));
					break;
	
				case SDL_QUIT:
					run = false;
					break;
			}
		}
		SDL_UpdateWindowSurface(window);

		// trying for about 33 frames per second (1000/30)
		SDL_Delay(30);
	}
	SDL_Quit();
	SDL_Log("%d", i);
}

This is not application code problem,
This is bug in libSDL rendering or bitmap or somewhat
A libSDL code guru is needed to get idea what the bug may be, looking to the broken window

Not meant to be rude, but do you really believe that someone is going to find the issue in unknown port by looking at a picture? While it is possible that someone else may be facing the same thing, your environment is quite specific, so I doubt that a theoretical solution would be applicable for you.