why do i get this unhandled exception for 3ds file that i tried to load in opengl?

0

so i tried to load a 3ds image in opengl using c++, but everytime i tried to run the program, it's always break at some point of the program. I'm trying to figure it out by looking for the problem at internet but i haven't find any. This is the error message Unhandled exception at 0x7AE3E73F (ucrtbased.dll) in ***.exe: 0xC0000005: Access violation writing location 0x004EF000.

and this is the part of the codes that has the problem

case 0x4120:
        fread(&l_qty, sizeof(unsigned short), 1, l_file);
        p_object->polygons_qty = l_qty;
        printf("Number of polygons: %d\n", l_qty);
        for (i = 0; i < l_qty; i++)
        {
            fread(&p_object->polygon[i].a, sizeof(unsigned short), 1, l_file);
            printf("Polygon point a: %d\n", p_object->polygon[i].a);
            fread(&p_object->polygon[i].b, sizeof(unsigned short), 1, l_file);
            printf("Polygon point b: %d\n", p_object->polygon[i].b);
            fread(&p_object->polygon[i].c, sizeof(unsigned short), 1, l_file);
            printf("Polygon point c: %d\n", p_object->polygon[i].c);
            fread(&l_face_flags, sizeof(unsigned short), 1, l_file);
            printf("Face flags: %x\n", l_face_flags);
        }
        break;
c++
opengl
3ds
asked on Stack Overflow Jun 14, 2020 by zainul muttaqin

1 Answer

1

Exception 0xC0000005 means you are accessing memory that does not belong to you (segmentation fault or Access violation...). The location 0x004EF000 is the offset in your local memory space where you are accessing wrongly (read or write).

If you check all your pointers and found one close to that but slightly smaller to that number you probably found the stuff you are accessing out of bounds.

If the number is small that usually means you are using a NULL pointer. Your location is ~5MByte from zero so if you have some array or class that big its most likely the case that you are using a NULL pointer to it instead of real address ...

That can happen when variable names are fighting, or when you have error in passing pointers logic, or when you are multithreding without locks, or if you forgot to new something or not testing if new is out of memory ...

answered on Stack Overflow Jun 14, 2020 by Spektre

User contributions licensed under CC BY-SA 3.0