Geeks With Blogs

News

Series

Add to Technorati Favorites


An Archived Managed World This blog has moved to http://www.managed-world.com/blog

[Crosspost from Managed World]

There is a bug in the sample framework ResourceCache where if you create more than a single font using the method call ResourceCache.GetInstance().CreateFont(), even if they are different fonts, the call will fail the majority of the time. It appears this happens because the key for the Hashtable used in the ResourceCache is the FontDescription structure itself and the FontDescription does not override the GetHashCode() method from object (resulting in differing FontDescription instances actually returning the same hashcode).

So, because of how the method determines whether the font has already been added (it doesn't use .ContainsKey()), the call will fail when the attempt is made to actually add the second font to the hashtable because the key already exists.

If you wish to replicate this, simply use the empty project template and add another line of code after the setting of statsFont to re-initialize statsFont again to a different font.

There is a quick workaround for this. Since the sample framework is just source code, you can actually just calculate the hashcode for the structure yourself and use your calculated hashcode for the key (and don't go through GetHashCode). At least it's a workaround until it is fixed in the framework (which is probably a pretty darn low priority since it is just the sample framework).

Posted on Monday, July 4, 2005 8:13 PM Game Development | Back to top


Comments on this post: BUG: Sample Framework, ResourceCache..CreateFont

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Jason Olson | Powered by: GeeksWithBlogs.net