Document that the pitch value may be zero for surfaces that will be filled in by the application later.

Also verify that the pitch isn't zero for surfaces with valid pixels

Fixes https://github.com/libsdl-org/SDL/issues/7143
This commit is contained in:
Sam Lantinga
2023-01-24 22:49:33 -08:00
parent e3bada6fbd
commit d496d187c5
3 changed files with 28 additions and 12 deletions

View File

@@ -203,7 +203,6 @@ SDL_CreateSurfaceFrom(void *pixels,
Uint32 format)
{
SDL_Surface *surface;
size_t minimalPitch;
if (width < 0) {
SDL_InvalidParamError("width");
@@ -215,20 +214,26 @@ SDL_CreateSurfaceFrom(void *pixels,
return NULL;
}
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
int p;
if (SDL_CalculateYUVSize(format, width, height, NULL, &p) < 0) {
if (pitch == 0 && pixels == NULL) {
/* The application will fill these in later with valid values */
} else {
size_t minimalPitch;
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
int p;
if (SDL_CalculateYUVSize(format, width, height, NULL, &p) < 0) {
SDL_InvalidParamError("pitch");
return NULL;
}
minimalPitch = p;
} else {
minimalPitch = SDL_CalculatePitch(format, width, SDL_TRUE);
}
if (pitch < 0 || (size_t)pitch < minimalPitch) {
SDL_InvalidParamError("pitch");
return NULL;
}
minimalPitch = p;
} else {
minimalPitch = SDL_CalculatePitch(format, width, SDL_TRUE);
}
if (pitch < 0 || (pitch > 0 && ((size_t)pitch) < minimalPitch)) {
SDL_InvalidParamError("pitch");
return NULL;
}
surface = SDL_CreateSurface(0, 0, format);