[Gelöst]glGenTextures verursacht Speicherfehler
-
Also glGenTextures verursacht, wie schon im Titel stehend, einen Speicherfehler, ich komm aber nicht drauf, wo das Problem liegt. Ich wäre über einen Tip sehr dankbar.
Meine Main sieht wie folgt aus:
int main(int argc, char* argv[]) { cin>>num_pics; //read BMP files BMPInit(num_pics); //init/allocate the bitmapsources with the data out of the BMPfiles initRGBbitmapsource(pictures, num_pics); //fill the bitmapsources with the BMP-Data bmptobitmapsource(pixels, pictures, num_pics); //init the OpenCL device(s) CLInit(); //create the OpenCL buffers initCLbuffer(pictures, num_pics); //fill the hostinputbuffer with the Data of the pictures and add the border conditions. //The inputbuffer will never changed during the program fillhostbuffer(pictures, num_pics); strcpy(w_title, "Init Program"); glutInit(&argc, argv); glutInitWindowPosition(100,10); glutInitWindowSize(600,600); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(w_title); GLInit(); glutDisplayFunc(displayfunc); glutOverlayDisplayFunc(overlaydisplayfunc); glutReshapeFunc(reShape); glutKeyboardFunc(keyboardFunc); glutMouseFunc(mouseFunc); glutIdleFunc(idle); //start endless loop glutMainLoop(); return 0;
Die GLInit sieht wie folgt aus:
void GLInit() { cout<<"#############"<<endl; cout<<"INIT OpenGL"<<endl; cout<<"#############"<<endl; glClearColor(0.0 ,0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glEnable(GL_TEXTURE_2D); GLsizei size=num_pics; glGenTextures(size,tex_obj); //generate num_pics texture objects with names tex_obj[0] to [num_pics-1] }
Funktioniert auch alles soweit, nur eben glGenTextures verursacht immer einen Speicherfehler...
Bin ziemlich ratlos. Ich hab per google mal nach dem Problem geschaut. Da hies es, dass der GL Context eventuell noch nicht erzeugt sei, aber das kann ja eigentlich nicht sein, da ich ja vorher das Fenerst erzeuge, und die Funktion auch zurück kommt (glutInit(&argc, argv)& GlutCreateWindow(w_title)).
EDIT:
Das Ganze mach ich daglTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, pictures[pic].info.biWidth, pictures[pic].info.biHeight, 0, GL_RGB, GL_FLOAT, pixels[pic]);
mir einen Fehler bringt, ebenfalls einen Speicherfehler...
ich denke, das liegt an pixels, weiß aber nicht so recht, woran das liegen könnte.
erzeugt wird das wie folgte:
void initRGBbitmapsource(bmp_file* pictures, int num_pics){ //allocate space for every picture with the following structure: bitmapsources[num_picture][Height][Width][RGB] pixels = new GLfloat*** [num_pics]; for(int i=0; i<num_pics; i++){ pixels[i] = new GLfloat** [pictures[i].info.biHeight]; for(int j=0; j<pictures[i].info.biHeight; j++){ pixels[i][j] = new GLfloat* [pictures[i].info.biWidth]; for(int k=0; k<pictures[i].info.biWidth; k++){ pixels[i][j][k]= new GLfloat [3];//TODO change this into RGBA } } } }
Das funktioniert auch tadellos, genau wie das Befüllen mit:
bmptobitmapsource(GLfloat**** bitmapsources, bmp_file* pictures, int num_pics){ cout<<"Load BMP-Data into the bitmapsources"<<endl; int wrap_size; for(int pic=0; pic<num_pics; pic++){ //check if there is alignment or not if((pictures[pic].info.biWidth*3)%4==0){ wrap_size=pictures[pic].info.biWidth*3; } else{ wrap_size=pictures[pic].info.biWidth*3 + 4-(pictures[pic].info.biWidth*3)%4; } int h, b; for (h = 0; h < pictures[pic].info.biHeight; h ++){ for (b = 0; b < pictures[pic].info.biWidth; b ++){ bitmapsources[pic] [h] [b] [0] = float(pictures[pic].bild[h*wrap_size+b*3 ])/255; /*R*/ bitmapsources[pic] [h] [b] [1] = float(pictures[pic].bild[h*wrap_size+b*3+1])/255; /*G*/ bitmapsources[pic] [h] [b] [2] = float(pictures[pic].bild[h*wrap_size+b*3+2])/255; /*B*/ } } } }
pic ist btw. auch als globale Variable anzutreffen, daher passt das schon im glTexImage2D mit dem pic.
wäre cool, wenn ihr eine Idee habt.
-
Hast du in dem Thread wo das passiert zu dem Zeitpunkt wo es passiert einen gültigen GL Context?
-
Ich hab nur eine single-Thread Anwendung. Ich gehe also davon aus, dass der Context da sein sollte.
Ich hab auch geschaut, wie ich das prüfen kann, aber nur für irgendwelche Libaries etwas gefunden und nicht für OpenGL direkt. Bei Glut hab ich auch nichts gefunden.
-
Ok Leute, JETZT versteh ich die Welt wirklich nicht mehr
GLfloat**** pixels; pixels = new GLfloat*** [num_pics]; for(int i=0; i<num_pics; i++){ pixels[i] = new GLfloat** [pictures[i].info.biHeight]; for(int j=0; j<pictures[i].info.biHeight; j++){ pixels[i][j] = new GLfloat* [pictures[i].info.biWidth]; for(int k=0; k<pictures[i].info.biWidth; k++){ pixels[i][j][k]= new GLfloat [3];//TODO change this into RGBA } } }
führt zu dem bekannten Fehler
GLfloat*** tex; tex = new GLfloat** [pictures[pic].info.biHeight]; for(int j=0; j<pictures[pic].info.biHeight; j++){ tex[j] = new GLfloat* [pictures[pic].info.biWidth]; for(int k=0; k<pictures[pic].info.biWidth; k++){ tex[j][k]= new GLfloat [3];//TODO change this into RGBA } }
funktioniert aber problemlos
WTF? Das ist doch absolut der gleiche Code.....
ich übergeb halt einmal pixels[pic] und das andere tex.
Mit tex funktionierts mit pixels[pic] nicht.... Ich hab echt KEINEN schimmer, warum das eine geht und das andere nicht. Jemand eine Idee?
BTW:
Muss ich eigentlich für die Texutrdaten als Format daten[HOEHE][BREITE][#Kanäle] haben? oder kann ich das auch in einen 1D array packen? Hab dazu nichts gefunden
-
Ein Vier-Sterne-Programmierer? Leg noch einen drauf, und du kannst ein Nobelrestaurant eröffnen ...
-
Und wo ist das Problem? So hab ich halt alles beeinander...
Ich hab jetzt aber selbst herausgefunden, das man auch 1D-Arrays verwenden kann ohne Probleme. Das macht mir die Arbeit sehr viel einfacher.
Mit
glPixelStorei (GL_UNPACK_ALIGNMENT, 2);
kann ich scheinbar auch direkt die BMP Datan verwenden, was praktisch ist, da ich mir dann das ganze gebuffere sparen kann, nur um das Anfangsbild ausgeben zu können.
Warum ich mit dem pixels ein Problem habe verstehe ich allerdings noch immer nicht...
EDIT
glGenTextures bringt jetzt allerdings noch immer das selbe Problem...Was dabei auch selbstam ist, ist kann ja die 2D Textur verwenden, aber glGenTextures verursacht noch immer den Fehler.
Wie sieht das eigentlich jetzt aus. Ich hab ja RGB, muss aber für jeden einzelnen Kanal ein eigenes array anlegen, um damit vernünfitg arbeiten zu können. Wie kann ich denn am Besten auf den 3 Einzelwerten ein gemeinsames array wieder anlegen?
Geht dass dann per glTexSubImage2D?
Also das ich die Textur nacheinander mit R G und B fülle.
EDIT2:
Ok, ich hab das Problem mit glGenTextures gelöst....Ich Idiot hab das Array nicht initilisiert...
-.-
Ich bin davon ausgegangen, das man nur einen GLuint Pointer übergeben muss, und den Rest OpenGL bewerkstelligt... Tja, dem ist nicht so. Man muss schon selbst ausreichend Speicher allocieren -.-
Damit wäre dieses "Problem" dann auch gelöst...
Über einen Tip bzgl. dem zusammenführen von einzelnen Farbkanälen in eine einzelne Textur wäre ich aber noch immer dankbar