Pregunta

I have an error I don't know how to solve.

I created a simple program, using VS2012, in order to test SOIL (sample code from SOIL's website):

#include "SOIL.h"
#include <iostream>
#include <glew.h>
#include <freeglut.h>

int main() {
std::cout << "Started" << std::endl;

/* load an image file directly as a new OpenGL texture */
GLuint tex_2d = SOIL_load_OGL_texture
    (
    "img.png",
    SOIL_LOAD_AUTO,
    SOIL_CREATE_NEW_ID,
    SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    );

/* check for an error during the load process */
if( 0 == tex_2d )
{
    printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}
}

I get the error:

Unhandled exception at 0x585727FF (msvcr110d.dll) in imageLib.exe: 0xC0000005: Access violation reading location 0x00000000.

Any help is appreciated. Thank you.

¿Fue útil?

Solución

All I did was to make sure GL was loaded before trying to use a GLuint as Necrolis suggested.

If you have the library loaded correct, this small example should run without errors (does not display anything, but shows the order of GL and SOIL:

#include "SOIL.h"
#include <iostream>
#include <glew.h>
#include <freeglut.h>

#define WINDOW_WIDTH  800
#define WINDOW_HEIGHT 600

void LoadTexture() {
/* load an image file directly as a new OpenGL texture */
GLuint tex_2d = SOIL_load_OGL_texture
    (
    "Data/img.png",
    SOIL_LOAD_AUTO,
    SOIL_CREATE_NEW_ID,
    SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    );

/* check for an error during the load process */
if( 0 == tex_2d )
{
    printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
}

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

int main(int argc, char** argv) {
std::cout << "Started" << std::endl;

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tutorial 15");

glutSwapBuffers();

LoadTexture();

glEnable(GL_TEXTURE_2D);                            // Enable Texture Mapping ( NEW )
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

glutMainLoop();

return 0;
}

Otros consejos

I have faced with these issue so many times. I think this is caused by absence of error handling SOIL library.

when loading your image data ,the path may be incorrect. In my cases, I write the path like in that form;

C:/Users/User/Pictures/texture.JPG

but when I change this path like that, there is no error when building the project ;)

file:///C:/Users/User/Pictures/texture.JPG
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top