perhaps the actual code would help us see what’s happening.
Ok. Here’s where the pixel pointer becomes NULL:
void Sprite::draw(int x, int y)
{
SDL_Rect rect;
if (!valid)
fatal_error(“Sprite is invalid”);
rect.x = x;
rect.y = y;
SDL_BlitSurface(bitmap, NULL, screen, &rect);
}
That gets called first, and then later this function (in the same object)
gets called:
void Sprite::draw(int x, int y, int w, int h)
{
SDL_Rect rect;
if (!valid)
fatal_error(“Sprite is invalid”);
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
GDL_stretch_blit(bitmap, NULL, screen, &rect);
}
And here’s GDL_stretch_blit() that was just called:
// A clipping wrapper function for SDL_SoftStretch(), since it just doesn’t
// draw anything at all if any part of src or dest is outside legal limits.
// It also clips to the dest clipping area.
//
// Note: The clipping isn’t perfect, and some distortion occurs due to
// integer rounding off. It’s good enough for my needs, though, not to
// mention I don’t feel like messing around with the math involved with
// this any more than I have already in this function. If you want to
// try and improve it, then look at xmag and ymag, and do clipping one way
// if it’s >= 1 or do it the other way if it’s < 1. It’s about as hard to
// explain as writing the code would be to do it, but that should point you
// in the right direction.
//
int GDL_stretch_blit(SDL_Surface *src, SDL_Rect *src_rect, SDL_Surface
*dest, SDL_Rect *dest_rect)
{
int sx, sy, sw, sh, mw, mh, cx, cy, cw, ch, dif;
int dx, dy, dw, dh, z;
float xmag, ymag;
SDL_Rect src_temp, dest_temp;
/* Make sure the surfaces aren’t locked */
if (!src || !dest) {
SDL_SetError(“GDL_particle_blit: passed a NULL surface”);
return -1;
}
if (src->locked || dest->locked) {
SDL_SetError(“Surfaces must not be locked during blit”);
return -1;
}
if (dest_rect) {
dx = dest_rect->x;
dy = dest_rect->y;
dw = dest_rect->w;
dh = dest_rect->h;
} else {
dx = dy = 0;
dw = dest->w;
dh = dest->h;
dest_rect = &dest_temp;
}
// nothing there…
if ((dw < 1) || (dh < 1))
return 1;
// clip source rectangle to source surface area
if (src_rect) {
sx = src_rect->x;
sy = src_rect->y;
sw = src_rect->w;
sh = src_rect->h;
xmag = float(dw) / float(sw);
ymag = float(dh) / float(sh);
if (sx < 0) {
z = int(sx * xmag);
dx -= z;
dw += z;
sw += sx;
sx = 0;
}
if (sy < 0) {
z = int(sy * ymag);
dy -= z;
dh += z;
sh += sy;
sy = 0;
}
mw = src->w - sx;
mh = src->h - sy;
if (sw >= mw) {
dw -= int((sw - mw) * xmag);
sw = mw;
}
if (sh >= mh) {
dh -= int((sh - mh) * ymag);
sh = mh;
}
} else {
sx = sy = 0;
sw = src->w;
sh = src->h;
xmag = float(dw) / float(sw);
ymag = float(dh) / float(sh);
src_rect = &src_temp;
}
// clip target rectangle to target surface clip rectangle
cx = dest->clip_rect.x;
cy = dest->clip_rect.y;
cw = dest->clip_rect.w;
ch = dest->clip_rect.h;
dif = cx - dx;
if (dif > 0) {
z = int(dif / xmag);
sx += z;
sw -= z;
dx += dif;
dw -= dif;
}
dif = dx + dw - cx - cw;
if (dif > 0) {
sw -= int(dif / xmag);
dw -= dif;
}
dif = cy - dy;
if (dif > 0) {
z = int(dif / ymag);
sy += z;
sh -= z;
dy += dif;
dh -= dif;
}
dif = dy + dh - cy - ch;
if (dif > 0) {
sh -= int(dif / ymag);
dh -= dif;
}
if ((sw < 1) || (sh < 1))
return 1;
src_rect->x = sx;
src_rect->y = sy;
src_rect->w = sw;
src_rect->h = sh;
dest_rect->x = dx;
dest_rect->y = dy;
dest_rect->w = dw;
dest_rect->h = dh;
return SDL_SoftStretch(src, src_rect, dest, dest_rect);
}
-Jason
I think I might have found a bug. I have an SDL_Surface that has pixel
data, but after I make a call to SDL_BlitSurface() the pixel data
pointer is
NULL. Anyone know why that might happen? Maybe that’s not a bug.
Maybe
it’s just shifting it to hardware video and so now requires a lock
before
accessing the pixels. However, I later call SDL_SoftStretch() with it
and
it crashes internally somewhere, which I assume is because the pixel
pointer
is NULL.
Can anyone verify this in the code?
Here’s the context of my situation if it helps:
- Windows 2000 with desktop bpp of 16.
- SDL screen created with software surface flag only specified. 16 bit
surface requested.
- The bitmap surface this problem is occuring with is 16 bits as
well. I
used SDL_ConvertSurface(). Created with the flags SDL_SRCCOLORKEY |
SDL_RLEACCEL. After the blit that sets the pixel pointer to NULL the
flags
are SDL_SRCCOLORKEY | SDL_RLEACCEL | SDL_RLEACCELOK.
Need any more info, let me know.
-Jason
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
----- Original Message -----
From: leimbacd@bellsouth.net (David Leimbach)
To:
Sent: Thursday, March 14, 2002 7:18 PM
Subject: Re: [SDL] bug I think