Yup - that fixed the other bug I was having! Thanks. But the removal of the node still does not succeed.
TIME MEMBERS
tm_sec : 8782144
tm_min : 8795676
tm_hour : 8795676
tm_mday : 8782160
tm_mon : 8782160
tm_year : 8782168
tm_wday : 8782168
tm_yday : 8782176
tm_isdst : 8782176
BOOLEAN VALUES
Remove : TRUE
Flagged to Remove : TRUE
Ignore day field? : TRUE
Ignore the week day?: FALSE
Ignore month field? : FALSE
Ignore year field? : FALSE
REMAINING FIELDS
Event Description : TEST: Manual
The first time through, the tm node contains the correct values, after deleting the nodes marked for deletion I check the list again, and I should not see the output from above. It should be gone. However as you can see the tm_* members have garbage in them, they appear to have been deleted correctly. The actual node itself is still there, the links are unbroken.
I have checked that the insertion routine is correct, I can follow the links in both directions, so I am conviced the problem lies in this code.
Code:
typedef struct eventNode
{
tm *time;
bool remove;
bool flaggedToRemove;
bool ignoreDayField;
bool ignoreWeekDayField;
bool ignoreMonthField;
bool ignoreYearField;
string eventDesc;
eventNode *next;
eventNode *prev;
} EVENT_NODE;
Memory is allocated for the tm structure and all values are copied to the members. Then memory is allocated for the node itself.
Code:
int CGameTime::removeNodes(void)
{
EVENT_NODE *current;
EVENT_NODE *temp;
int numOfNodesRemoved = 0;
current = head;
while(current != NULL)
{
if (current->flaggedToRemove)
{
temp = current->next;
if( current->prev )
current->prev->next = current->next;
if( current->next )
current->next->prev = current->prev;
delete current->time;
delete current;
// Update the counters
numOfNodesRemoved++;
numberOfEvents--;
current = temp;
}
else
current = current->next;
}
nodesToRemove = false; // There are no further nodes to be removed
return numOfNodesRemoved;
}
Above is the modified code containing the changes suggested above.