0xC0000005: Access violation reading location 0x00000000C284EFA2

0

The project I was given to mess with utilizes openGL, C, and Tcltk. I am currently debugging a memory leak using Tcl memory tracing tools. Here is the snippet of code that is causing the error:

//there is a check here to make sure context isn't null i.e. if(context != NULL)
glRotatef(context[model_index].rotation[0], 1, 0, 0); //error occurs here, sometimes varies between each
glRotatef(context[model_index].rotation[1], 0, 1, 0);
glRotatef(context[model_index].rotation[2], 0, 0, 1);

Error output:

Exception thrown at 0x00007FFFF1C9AB21 (tkogl2.dll) in rsession.exe: 0xC0000005: Access violation reading location 0x00000000C284EFA2

Here is some additional code to give some reference for exactly what context is and how it is being used:

//struct definition and intilization
typedef struct {
    float x;
    float y;
    float z;
    float scale;
    float rotation[3];
} context_t;
context_t* context = NULL;

//memory allocation
if (context != NULL)
{
    ckfree((char*)context);
    context = NULL;
}
if (amount > 0) 
{
    context = (context_t*)ckalloc(amount*sizeof(context_t));
}

I thought perhaps model_index was for some reason too large and making it go out of bounds, but fixing it to 0 still caused the same error. If context != NULL is a proper way to check that context actually exists, then it shouldn't be NULL when executing. I lack the knowledge to pursue any additional options that could be causing this, so I hope to gain insight on potential avenues I could look at to explore this issue in more detail.

Here are some pieces of code that assign values to attributes of context:

//rotations
const char* attr = Tcl_GetStringFromObj(objv[1], NULL);
    if (strcmp(attr, "angle") == 0)
    {
        if (model_amount == 0)
        {
            return TCL_OK;
        }
        const char* d = Tcl_GetStringFromObj(objv[2], NULL);
        double r;
        Tcl_GetDoubleFromObj(interp, objv[3], &r);
        /*apply rotations*/
        switch (d[0]) {
        case 'x':
            context[model_index].rotation[0] += (float)r;
            ANGLE_REDUCE(context[model_index].rotation[0]);
            break;
        case 'y':
            context[model_index].rotation[1] += (float)r;
            ANGLE_REDUCE(context[model_index].rotation[1]);
            break;
        case 'z':
            context[model_index].rotation[2] += (float)r;
            ANGLE_REDUCE(context[model_index].rotation[2]);
            break;
        }
        char* msg = ckalloc(512);
        sprintf(msg, "Rotate: %f %f %f",
            context[model_index].rotation[0],
            context[model_index].rotation[1],
            context[model_index].rotation[2]);
        Tcl_SetResult(interp, msg, TCL_DYNAMIC);

        Tcl_ValidateAllMemory(__FILE__, __LINE__);
    }

//scaling
if (model_amount == 0)
        {
            return TCL_OK;
        }

        const char* value = Tcl_GetStringFromObj(objv[2], NULL);
        /*apply scaling*/
        if (strcmp(value, "in") == 0)
        {
            context[model_index].scale += 0.1;
        }
        else if (strcmp(value, "out") == 0 && context[model_index].scale > 0.1)
        {
            context[model_index].scale -= 0.1;
        }

It appears it also generates the error 0xffffffffffffffff

c
opengl
memory
asked on Stack Overflow Mar 5, 2020 by hkj447 • edited Mar 6, 2020 by hkj447

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0