1

这是我从 VS2010 收到的错误消息:

AzimuthalEqui.e​​xe 中 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 = "数据/texture.jpg"

SOIL_LOAD_AUTO (= 0)

SOIL_CREATE_NEW_ID (=0)

SOIL_flags = 16 (=SOIL_FLAG_INVERT_Y)

问题是当我包含一个我为解析文本文件中的某些信息而编写的文件时,会生成错误,否则会加载并显示纹理。这个问题很可能是由一个函数引起的,因为当这个特定函数被删除时,代码会加载并显示纹理。这是添加到我的项目时导致错误发生的功能:

[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;
}
4

1 回答 1

0

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

于 2012-08-14T03:36:40.437 回答