visual-studio-2010pointersrecursioncudd

Access violation reading location using Cudd


I am trying to implement an algorithm in Visual C using Cudd package. I have to use a function recursively. But it keeps throwing an error at one particular line. Error is Access violation reading location 0x00594a5ct. And it is coming against the usage of temp_bdd_result. I am unable to figure out why is this happening because both values used in temp_bdd_result-bdd_node & bdd_result are containing values. So why are they not accessible. Or this error points to some thing else that I am not able to see. Please Help.

DdNode* Path_Function_Construct(DdManager *manager,int matrix[3][3],int source)
{
DdNode *bdd_node,*bdd_result,*e,*temp_bdd_node,*temp_bdd_result;
if (source>=rows)
    return Cudd_ReadOne(manager);
else
{
    bdd_result=Cudd_ReadZero(manager);
    Cudd_Ref(bdd_result);
    for (int j=0;j<columns;j++)
    {
    if (matrix[source][j]==1)
    {
            //Declaring temp variables 

            //This means that an edge exists between source and node in consideration
            e=Cudd_bddNewVar(manager);
            Cudd_Ref(e);

            //Removing redundant nodes
            int new_matrix[3][3];
            for(int l=0;l<rows;l++)
                for(int m=0;m<columns;m++)
                    new_matrix[l][m]=matrix[l][m];
            for(int i=0;i<rows;i++)
                new_matrix[i][j]=0;

            //find path function using that node as a source
            temp_bdd_node=Path_Function_Construct(manager,new_matrix,j+1);

            Cudd_Ref(temp_bdd_node);
            bdd_node=Cudd_bddAnd(manager,e,temp_bdd_node);
            Cudd_Ref(bdd_node);
            temp_bdd_result=Cudd_bddIthVar(manager,4);
            temp_bdd_result=Cudd_bddAnd(manager,bdd_result,bdd_node); //this is where error is coming
            Cudd_Ref(temp_bdd_result);
            Cudd_RecursiveDeref(manager,bdd_result);
            bdd_result=temp_bdd_result;
            Cudd_Ref(bdd_result);
            Cudd_RecursiveDeref(manager,temp_bdd_node);
            Cudd_RecursiveDeref(manager,temp_bdd_result);
            Cudd_RecursiveDeref(manager,bdd_node);
            Cudd_RecursiveDeref(manager,e);
        } // end of if (matrix[source][j]==1)
    }// end of for loop
    return (bdd_result);
}
}

Solution

  • Cudd_RecursiveDeref() recursively deletes a node and all its child. So whenever bdd_node was dereferenced using Cudd_RecursiveDeref() bdd_result was also removed and its value was not returned by the function. So to retain the value for returning use Cudd_Deref() instead. It just decreases the reference count without deleting its child nodes.