This problem is really causing me distress. The following code crashes on line 9 with basically a null pointer error.
- /* Bind the texture using the data in tex_data */
- glGenTextures(1, &NewNode->tex);
- glBindTexture(GL_TEXTURE_2D, NewNode->tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- printf(“glTexImage2D…”);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, NewNode->size, NewNode->size, 0, GL_RGB, GL_FLOAT, NewNode->tex_data);
- printf("done
");
This never happened before when I was using a compile time three-demensional array such as tex_data=float[512][512][3], However, I wanted them to be dynamic so I wrote the code below to deal with that.
/* Use calloc to build a dynamic three-demensional array /
NewNode->tex_data=(float**)calloc(NewNode->size, sizeof(float*));
for(hh=NewNode->size-1;hh>=0;hh–) {
NewNode->tex_data[hh]=(float**)calloc(NewNode->size, sizeof(float*));
for(ww=0;ww<NewNode->size;ww++) {
NewNode->tex_data[hh][ww]=(float*)calloc(3, sizeof(float));
}
}
The runtime allocated array is accessable just like a compile time array, however, when I send it to glTexImage2D it crashes. If I switch back to the compile time array the program does not crash.
So, why would glTexImage2D not like the array I sent to it? Is their some difference between a three-demensioanl array to float *** of the same sort?