SpartanJ / SOIL2

SOIL2 is a tiny C library used primarily for uploading textures into OpenGL.
MIT No Attribution
370 stars 75 forks source link

Division by Zero in SOIL_load_OGL_texture on VS2017 15.9.11 #24

Closed SpartanJ closed 5 years ago

SpartanJ commented 5 years ago

Original report by Michael Legner (Bitbucket: Sokar, GitHub: Sokar).


Hi,

I'm currently working with the Book "Computer Graphics Programming in OpenGL with C++" ( http://merclearning.com/titles/Computer_Graphics_Programming_in_OpenGL_with_C++.html ) which uses your library to load textures.

Unfortunatly, I encountered a problem with it: just calling SOIL_load_OGL_texture as described in the book results in division by zero exception.

Code: GLuint texId = SOIL_load_OGL_texture(texFilePath.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y);

texFilePath is a std::string and valid path, otherwise SOIL results in "unable to fopen" error. Loading with stb_image.h works. I'm on Windows 10 x64 in Visual Studio 2017 Community Edition Version 15.9.11.

SpartanJ commented 5 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Hi Michael! Can you please share:

  1. A minimal working example.
  2. The source image.
  3. Indicate the line / the stack trace were the division by zero is happening.

Thanks.

SpartanJ commented 5 years ago

Original comment by Michael Legner (Bitbucket: Sokar, GitHub: Sokar).


Hi Martin,

If created a small application with which I can reproduce it just fine: https://bitbucket.org/Sokar/soil_issue24/src/master/ Only cloning the repo somewhere and starting the solution file with VS2017 should be enough to compile. I tried it on a second computer and it works fine.

the image use ist "img_test.bmp" from the bin folder of SOIL2.

I also got a bit more information, the exception happens in Line 1618 of Soil2.c which reads

#!c++

new_width = iwidth / reduce_block_x;

with reduce_block_x being zero.

soil2_issue24.PNG

I hope it helps to reproduce the exception.

SpartanJ commented 5 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


You must initialize an OpenGL context before trying to load any image. Your example will never work. It's crashing in that line because it's being unable to determine the max texture size, because there's no GL context to obtain it.

Regards

SpartanJ commented 5 years ago

Original comment by Michael Legner (Bitbucket: Sokar, GitHub: Sokar).


Your right. I just checked with a different project that has an OpenGL context initialized and works. I wasn't aware of that, even though it makes sense. And sorry for the delay, had some other stuff going on.

SpartanJ commented 5 years ago

Original comment by Michael Legner (Bitbucket: Sokar, GitHub: Sokar).


missing OpenGL context, not an actual bug.