In Novarunner, all models and sounds and other assets are loaded through the use of an AssetCache object. This guy basically follows this pattern:
public: T* obtain(string name): if(name is not in the dictionary of stuff we have): dictionary[name] = loadAsset return dictionary[name]protected: virtual T* loadAsset(string name) = 0;
Now spot the problem with this code:
class ModelCache : public AssetCache {public: virtual PropaneModel* loadAsset(string name) { ... }};// EntirelyUnrelatedCode.cppvoid letUsLoadSomeFreakingModelsAlready(ModelCache& models) { // Hey, why the fuck can I invoke a protected method here?!? PropaneModel* view = models.loadAsset(xmlnode.name);}
Basically, what my idiocy when I derived ModelCache allowed me to do was directly invoke the loadAsset method, which bypassed keeping a record of the model being loaded previously, so the model would be loaded over and over again because I was never actually using the cache part of the ModelCache.
To make life worse, since I'm working with raw pointers and the consumers of the PropaneModel* expect it to be freed elsewhere (i.e. in ModelCache), the meshes were never actually freed when necessary and we ended up with a pretty juicy runaway memory leak, which I would've noticed earlier if I could get the new Leaks tool in Xcode3 to work properly.
The reason why the loadModel method is public when it should be protected? Because I pulled out the AssetCache abstract class originally from it! [rolleyes] I should now, by law, invoke ApochPIQ's excellent post about frivolous and unnecessary refactoring.
I had assumed that one of the load methods would be protected and thus not allow me to invoke it from another piece of code (so I just picked the first load method that popped up in Code Sense), but since I had 'publicized' it, the 'dumb' load method was accepted instead.
Bork bork bork hoogen floogen
Link of the Day
Check out Ovine by Design and Smila's Exile remake. It's got gameplay thicker than War and Peace and you could spend a long time licking those graphics. Lick them, slave!
IT'S COMPANION CUBE!!