2016-05-06 4 views
5

Ich habe einen Weg zu meiner Datei bekam definiert auf diese Weise:C++ DevIL Funktion ilLoadImage - Beenden des Programms, Zugriffsverletzung

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

Und hier ist die Funktion, die ich verwende Bild laden:

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 

Was ist falsch in meinem Code? Warum fällt das Programm, wenn aufgerufen wird? Ich denke, dass file.c_str() sollte gut funktionieren als wchar_t * Art oder nicht? Vielen Dank für die Antwort :)

+0

Ich bin gespannt. Warum überhaupt wchar? Was passiert, wenn Sie mit Dateiname laden? – Andreas

+0

weil const char * ist nicht kompatibel mit const wchar_t * ... aber ich habe es herausgefunden ... das Problem ist nicht hier, ich habe nicht DevIl-Bibliothek mit 'ilInit() ;; – user3216673

Antwort

0

Als Autors gesagt, Sie ohne Initialisierung des lib ziemlich alles tun können: 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; 
} 

build:

g++ -Wall -pedantic --std=c++11 -g -o app main.cpp -lIL 
Verwandte Themen