don't crash on loading large textures

This commit is contained in:
David Rose 2002-02-27 15:39:39 +00:00
parent a7b3679165
commit 407cc9595c

View File

@ -3928,14 +3928,17 @@ apply_texture_immediate(Texture *tex) {
GLenum type = get_image_type(pb->get_image_type()); GLenum type = get_image_type(pb->get_image_type());
uchar *image = pb->_image; uchar *image = pb->_image;
uchar *locally_allocated_image = (uchar *)NULL;
if (!gl_supports_bgr) { if (!gl_supports_bgr) {
// If the GL doesn't claim to support BGR, we may have to reverse // If the GL doesn't claim to support BGR, we may have to reverse
// the byte ordering of the image. // the byte ordering of the image.
if (external_format == GL_RGB && pb->get_image_type() == PixelBuffer::T_unsigned_byte) { if (external_format == GL_RGB && pb->get_image_type() == PixelBuffer::T_unsigned_byte) {
image = (uchar *)alloca(num_pixels * 3); locally_allocated_image = new uchar[num_pixels * 3];
image = locally_allocated_image;
uchar_bgr_to_rgb(image, pb->_image, num_pixels); uchar_bgr_to_rgb(image, pb->_image, num_pixels);
} else if (external_format == GL_RGBA && pb->get_image_type() == PixelBuffer::T_unsigned_byte) { } else if (external_format == GL_RGBA && pb->get_image_type() == PixelBuffer::T_unsigned_byte) {
image = (uchar *)alloca(num_pixels * 4); locally_allocated_image = new uchar[num_pixels * 4];
image = locally_allocated_image;
uchar_bgra_to_rgba(image, pb->_image, num_pixels); uchar_bgra_to_rgba(image, pb->_image, num_pixels);
} }
} }
@ -3963,18 +3966,23 @@ apply_texture_immediate(Texture *tex) {
#ifndef NDEBUG #ifndef NDEBUG
if (gl_show_mipmaps) { if (gl_show_mipmaps) {
build_phony_mipmaps(tex); build_phony_mipmaps(tex);
return true; } else
}
#endif #endif
gluBuild2DMipmaps(GL_TEXTURE_2D, internal_format, {
xsize, ysize, gluBuild2DMipmaps(GL_TEXTURE_2D, internal_format,
external_format, type, image); xsize, ysize,
external_format, type, image);
#ifndef NDEBUG #ifndef NDEBUG
if (gl_save_mipmaps) { if (gl_save_mipmaps) {
save_mipmap_images(tex); save_mipmap_images(tex);
} }
#endif #endif
}
report_errors(); report_errors();
if (locally_allocated_image != (uchar *)NULL) {
delete[] locally_allocated_image;
}
return true; return true;
} }
} }
@ -3984,6 +3992,10 @@ apply_texture_immediate(Texture *tex) {
xsize, ysize, pb->get_border(), xsize, ysize, pb->get_border(),
external_format, type, image); external_format, type, image);
report_errors(); report_errors();
if (locally_allocated_image != (uchar *)NULL) {
delete[] locally_allocated_image;
}
return true; return true;
} }