以下是我从VS2010接收到的错误消息:
AzimuthalEqui.exe中0x77358dc9处未处理的异常:
0xC0000005:访问冲突写入位置0x00000014。
生成此错误的代码行是:

texture[1] = SOIL_load_OGL_texture
    (
        texture_filename,
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID, // create ID automatically
        SOIL_flags
    );

在进入此功能之前:
texture_filename=“Data/texture.jpg”
土壤荷载自动(=0)
土壤创建新ID(=0)
土壤标志=16(=土壤标志反向)
问题是,当我在文本文件中包含一个用于解析某些信息的文件时,将生成一个错误,否则将加载并显示纹理。prob很可能是由一个函数引起的,因为当这个特定的函数被移除时,代码将加载并显示纹理。
下面是添加到我的项目中时出错的函数:
[CODE]
void get_user_points(double *lats, double *longs){

    char buffer[BUFFSIZE_PARSE];
    char *p_buff = buffer;
    FILE *fp;
    const char *filename = "Points.txt";
    double temp;
    double *tmp_p = &temp;


    fp = fopen(filename,"r+");
    if (fp == NULL)
    {
        sprintf(buffer, "Can't Find File: %s", filename);
        MessageBoxA(NULL, buffer, "ERROR", MB_OK|MB_ICONEXCLAMATION);
        exit(0);
    }

    fgets(buffer, BUFFSIZE_PARSE, fp);

    while (*(p_buff+1) != '\0'){

        p_buff = get_next_letter(p_buff);

        switch (tolower(*p_buff)){
            case 'n':
                putchar(*p_buff);
                p_buff++;
                p_buff=get_next_double(lats, p_buff);
                printf(" = %f\n", *lats);
                break;
            case 's':
                ...
                ...
        }
    }
    putchar('\n');
    fclose(fp);
}

它与打开文件进行读取有关。。。如果我注释掉这些行,纹理将正确加载:
//fpr = fopen(filename2,"rb");
...
...
...
//fclose(fpr);

这是我的简化代码(我不认为这是问题,但只是以防万一)。[可能还有一些还押候审者我的全部密码]:
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

    {
        printf("Initialising...\n");
        glutInitWindowSize(700, 700);
        glutInitWindowPosition(0, 0);
        glutCreateWindow ("SOIL Texture Test");
    }

    InitGL();
    glutDisplayFunc(DrawGLScene);
    glutReshapeFunc(ReSizeGLScene);

    glutMainLoop();

    return 0;
}

int InitGL(GLvoid) // Setup OpenGL
{
    //Load textures
    if (!LoadGLTextures())                              // Jump To Texture Loading Routine ( NEW )
    {
        MessageBox(NULL,TEXT("Cannot Load Image for Texture Map"),TEXT("Error!"),MB_OK | MB_ICONINFORMATION);
        //return false;                                 // If Texture Didn't Load Return FALSE ( NEW )
    }
    else
        glEnable(GL_TEXTURE_2D);                        // Enable texture mapping


    glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);               // Set the background colour (to black)

    glClearDepth(1.0f);                                 // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
    glDepthFunc(GL_LEQUAL);                             // Select testing type


    //get_user_points(&user_lat[0], &user_long[0]);

    return true;                                        // Initialization went OK
}


void DrawGLScene(GLvoid) // OpenGL drawing function
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the Screen and the Depth Buffer

    glLoadIdentity();
    glTranslatef(0.0f,0.0f,z);

    glBindTexture (GL_TEXTURE_2D, texture[filter]);
    glBegin (GL_QUADS);
        glNormal3f(0, 0, 1);

        glTexCoord2f (0,0);
        glVertex3f (-3,-3 ,0);
        glTexCoord2f (1,0 );
        glVertex3f (3,-3 , 0);
        glTexCoord2f (1, 1);
        glVertex3f (3,3 , 0);
        glTexCoord2f (0,1 );
        glVertex3f (-3,3 ,0 );
    glEnd();

    glFlush();
}

void ReSizeGLScene(int w, int h) // Code to resize (and initialise) the OpenGL scene (run once when in fullscreen mode)
{
    // Set up perspective view matrix
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, (GLfloat)w/(GLfloat)h, 0.1f, 100.0f);
    //glOrtho(-50.0, 50.0, -50.0, 50.0, -50.0, 50.0);

    // Set up modelview matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

int LoadGLTextures(void) // Load Bitmaps And Convert To Textures
{
    unsigned int SOIL_flags;
    GLint mag_param;
    GLint min_param;

    printf("Loading Textures... ");

    SOIL_flags = SOIL_FLAG_INVERT_Y;
    mag_param = GL_NEAREST;
    min_param = GL_NEAREST;


    texture[1] = SOIL_load_OGL_texture
    (
        texture_filename,
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID, // create ID automatically
        SOIL_flags
    );

    if(texture[1] == 0)
        return false;

    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag_param);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min_param);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    printf("Textures Loaded\n");
    return true;
}

最佳答案

在我的项目中包含.c文件而不是.lib文件解决了这个问题。

10-08 02:53