while (len) {
target_ulong start_page = TARGET_PAGE(start_addr);
target_ulong start_pa = gles2_pa(s, start_page, 0);
+ if (!start_pa)
+ {
+ return 0;
+ }
#if (GLES2_DEBUG == 1)
target_ulong end_pa = start_pa;
#endif // GLES2_DEBUG == 1
while(end_page < last_page) {
target_ulong next_page = end_page + TARGET_PAGE_SIZE;
target_ulong next_pa = gles2_pa(s, next_page, 0);
+ if (!next_pa)
+ {
+ return 0;
+ }
// If the target pages are not linearly spaced, stop..
if((next_pa < start_pa) ||
while (len) {
target_ulong start_page = TARGET_PAGE(start_addr);
target_ulong start_pa = gles2_pa(s, start_page, access_type);
+ if (!start_pa)
+ {
+ return 0;
+ }
#if (GLES2_DEBUG == 1)
target_ulong end_pa = start_pa;
#endif // GLES2_DEBUG == 1
while(end_page < last_page) {
target_ulong next_page = end_page + TARGET_PAGE_SIZE;
target_ulong next_pa = gles2_pa(s, next_page, access_type);
+ if (!next_pa)
+ {
+ return 0;
+ }
// If the target pages are not linearly spaced, stop..
if ((next_pa < start_pa) ||
return count;
}
-static unsigned gles2_get_stride(unsigned bpp)
+static unsigned gles2_get_stride(unsigned width, unsigned bpp)
{
unsigned alignment = 0;
hgl.glGetIntegerv(GL_UNPACK_ALIGNMENT, (GLint *)&alignment);
- return (alignment > bpp) ? alignment : bpp;
+ if (!alignment)
+ {
+ alignment = 1;
+ }
+
+ return ((width * bpp) + alignment - 1) & ~(alignment - 1);
}
static void gles2_TransferArrays(gles2_State *s, gles2_Context *c,
GLES2_PRINT("Reading %dx%dx%d image at %d,%d...\n",
width, height, bpp, x, y);
- nbytes = width*height*gles2_get_stride(bpp);
+ nbytes = height*gles2_get_stride(width, bpp);
pixels = malloc(nbytes);
}
hgl.glReadPixels(x, y, width, height, format, type, pixels);
GLES2_PRINT("Uploading %dx%dx%d image...\n", width, height, bpp);
char* pixels = NULL;
if (pixelsp && width > 0 && height > 0) {
- TGLsizei nbytes = width*height*gles2_get_stride(bpp);
+ TGLsizei nbytes = height*gles2_get_stride(width, bpp);
pixels = malloc(nbytes);
gles2_transfer(s, pixelsp, nbytes, pixels, 0);
}
char *pixels = NULL;
if (pixelsp && width > 0 && height > 0) {
- TGLsizei nbytes = width*height*gles2_get_stride(bpp);
+ TGLsizei nbytes = height*gles2_get_stride(width, bpp);
pixels = malloc(nbytes);
gles2_transfer(s, pixelsp, nbytes, pixels, 0);
}