C ++ function DevIL ilLoadImage - program exit, access violation

I have a path to my file, which is defined as follows:

const char* GROUND_TEXTURE_FILE = "objects/textures/grass.jpg"; 

And here is the function that I use to upload the image:

 bool loadTexImage2D(const string &fileName, GLenum target) { ... // this will load image data to the currently bound image // at first, we must convert fileName, for ascii, this method is fine? wstring file(fileName.begin(), fileName.end()); if(ilLoadImage(file.c_str()) == IL_FALSE) { //here the program falls 

What is wrong in my code? Why ilLoadImage program crash when ilLoadImage is ilLoadImage ? I think file.c_str() should work fine as a wchar_t * type or not? Thanks for the answer:)

+5
source share
1 answer

As the author said, you can do anything without initializing lib: D

 #include <iostream> #include <IL/il.h> int main () { std::string filename = "objects/textures/grass.jpg"; ilInit(); if (!ilLoadImage(filename.c_str())) { std::cout << ilGetError() << std::endl; return 1; } std::cout << ilGetInteger(IL_IMAGE_WIDTH) << std::endl; std::cout << ilGetInteger(IL_IMAGE_HEIGHT) << std::endl; return 0; } 

assembly:

 g++ -Wall -pedantic --std=c++11 -g -o app main.cpp -lIL 
0
source

All Articles