Well, I believe the answer/problem is in these few lines:

SDL_Surface* thing;
SDL_LockSurface(thing);
put_pixel32(thing,2,2,SDLred);
SDL_UnlockSurface(thing);
apply_surface(0,0,thing,screen);
SDL_Flip(screen);

The locking/unlocking dosn't seem to do much, if I delete the lines the same thing happens, and if I check if it must lock before, the program still returns 3, etc.

Recommended Answers

All 4 Replies

Can you provide the shortest possible compilable example that produces the error ?

#include<SDL.h>
#include<windows.h>


void apply_surface(int x,int y,SDL_Surface* source,SDL_Surface* dest)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source,NULL,dest,&offset);
}


int main( int argc, char** argv )
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen = SDL_SetVideoMode(500,500,32,0);

SDL_Surface* thing;
SDL_LockSurface(thing);
//put_pixel32(thing,2,2,SDLred);
SDL_UnlockSurface(thing);
apply_surface(0,0,thing,screen);

SDL_Flip(screen);

SDL_Delay(1000);

SDL_Quit();
return 0;
}

Okay, Θats t.he shortest program possible.

Why are you trying to lock an uninitialized surface? This seems to work fine:

int main( int argc, char** argv )
{
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_Surface* screen = SDL_SetVideoMode(500,500,32,0);
	
	SDL_LockSurface(screen);
	SDL_UnlockSurface(screen);

	SDL_Flip(screen);

	SDL_Delay(1000);

	SDL_Quit();
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.