Epic failures in the game development field.

This blog covers funny/weird issues and bugs from games that happened during development.

Send your own contributions to igetyourfail at repi.se (can be anonymous if specified)

Friday, August 28, 2009

Giving New Meaning to Destructors


LRUCacheModel::~LRUCacheModel()
{
for( LRUCacheEntry* entry; entry != NULL; )
{
LRUCacheEntry* next = entry->next;
delete entry;
entry = next;
}
}

(Thanks to Pat)

4 comments:

Dave Powell said...

Hurray for uninitialized pointers.

On another note, anyone have thoughts on whether a for loop should have dummy semicolons if one/more of the three parts aren't used?

In this case,
for( LRUCacheEntry* entry = pFail; entry != NULL; ; ) {...}

Pat Wilson said...

It doesn't need the third semi-colon for GCC or Visual Studio, I am not sure what the standard says.

Jens Alfke said...

I'm ashamed to say it took me three readings to notice that 'entry' wasn't initialized. In my defense, it's well past the end of my workday and I've had two glasses of wine :)

I'm not sure I understand the question about semicolons. A 'for' statement always has two semicolons in it to delimit the three clauses, even if one or more of the clauses is missing. The code here follows that rule. I think adding more semicolons would just cause syntax errors.

Dave Powell said...

Looking back on this, it must have been a long day for myself as well. Ignore my question, please :)

Followers