From: Steinar H. Gunderson Date: Wed, 24 Feb 2016 00:32:49 +0000 (+0100) Subject: Do not send NULL to glTexSubImage2D if there is no input data set; it is illegal... X-Git-Tag: 1.4.0~16 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=274627c966f53780991e9f80887aa1906b592751 Do not send NULL to glTexSubImage2D if there is no input data set; it is illegal, and NVIDIA's drivers crash on it. --- diff --git a/flat_input.cpp b/flat_input.cpp index 0f6f395..8f24d86 100644 --- a/flat_input.cpp +++ b/flat_input.cpp @@ -66,7 +66,7 @@ void FlatInput::set_gl_state(GLuint glsl_program_num, const string& prefix, unsi glActiveTexture(GL_TEXTURE0 + *sampler_num); check_error(); - if (texture_num == 0) { + if (texture_num == 0 && (pbo != 0 || pixel_data != NULL)) { // Translate the input format to OpenGL's enums. GLint internal_format; GLenum format; diff --git a/flat_input_test.cpp b/flat_input_test.cpp index 741b7c7..2fb807e 100644 --- a/flat_input_test.cpp +++ b/flat_input_test.cpp @@ -320,4 +320,24 @@ TEST(FlatInput, ExternalTexture) { expect_equal(expected_data, out_data, 4, size); } +TEST(FlatInput, NoData) { + const int width = 2; + const int height = 4; + + float out_data[width * height]; + + EffectChainTester tester(NULL, width, height); + + ImageFormat format; + format.color_space = COLORSPACE_sRGB; + format.gamma_curve = GAMMA_LINEAR; + + FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height); + tester.get_chain()->add_input(input); + + tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR); + + // Don't care what the output was, just that it does not crash. +} + } // namespace movit diff --git a/ycbcr_input.cpp b/ycbcr_input.cpp index 071ce13..b0ca692 100644 --- a/ycbcr_input.cpp +++ b/ycbcr_input.cpp @@ -62,7 +62,7 @@ void YCbCrInput::set_gl_state(GLuint glsl_program_num, const string& prefix, uns glActiveTexture(GL_TEXTURE0 + *sampler_num + channel); check_error(); - if (texture_num[channel] == 0) { + if (texture_num[channel] == 0 && (pbos[channel] != 0 || pixel_data[channel] != NULL)) { GLenum format, internal_format; if (channel == 1 && ycbcr_input_splitting == YCBCR_INPUT_SPLIT_Y_AND_CBCR) { format = GL_RG; diff --git a/ycbcr_input_test.cpp b/ycbcr_input_test.cpp index 463cb7e..a5032af 100644 --- a/ycbcr_input_test.cpp +++ b/ycbcr_input_test.cpp @@ -688,4 +688,35 @@ TEST(YCbCrTest, WikipediaJPEGMatrices) { EXPECT_NEAR(128.0, offset[2] * 255.0, 1e-3); } +TEST(YCbCrInputTest, NoData) { + const int width = 1; + const int height = 5; + + float out_data[4 * width * height]; + + EffectChainTester tester(NULL, width, height); + + ImageFormat format; + format.color_space = COLORSPACE_sRGB; + format.gamma_curve = GAMMA_sRGB; + + YCbCrFormat ycbcr_format; + ycbcr_format.luma_coefficients = YCBCR_REC_601; + ycbcr_format.full_range = false; + ycbcr_format.num_levels = 256; + ycbcr_format.chroma_subsampling_x = 1; + ycbcr_format.chroma_subsampling_y = 1; + ycbcr_format.cb_x_position = 0.5f; + ycbcr_format.cb_y_position = 0.5f; + ycbcr_format.cr_x_position = 0.5f; + ycbcr_format.cr_y_position = 0.5f; + + YCbCrInput *input = new YCbCrInput(format, ycbcr_format, width, height); + tester.get_chain()->add_input(input); + + tester.run(out_data, GL_RGBA, COLORSPACE_sRGB, GAMMA_sRGB); + + // Don't care what the output was, just that it does not crash. +} + } // namespace movit