ivansafrin/Polycode — pull request #392 by Symphonym (2013-10-04 22:44:15+00:00)
Title: Screenrewrite

Alright, here comes my first contributions to Polycode. It consists mainly of fixing memory leaks and other things Valgrinds complains about. On a side note though, I believe Polycode should start using a smart pointer of some sort, perhaps making a small "PolyPtr" class to fit into Polycode more neatly.

Other things that I couldn't/haven't fixed:
+ "Scene sceen = new Scene(Scene::SCENE_2D);". Allocated on heap so that SceneManager can access it. I would recommend making a "Scene::createScene(...)" static factory function which returns a handle (a pointer) to the Scene. Then deletion of the Scene is handled by the SceneManager. I can take care of this, just need an ok from you.

+ Biggest (and last) memory leak that Valgrind complains about (atleast on Ubuntu 13.04), that's not a library, is deallocation of textures created within "Polycode::OpenGLRenderer::createTexture". These should be deleted in the destructor of the ResourceManager (I would assume), but deletions in there has some weird behaviour. Can't put deletes of materials, shaders and programs in one loop, needs to be separate. But deleting textures in a separate loop doesn't work (gives invalid read's in valgrind), so something is accessing them or deleting them somewhere else I would think.
+ Example in Release/.../Template folder is missing a "-lX11" link command at the end of the LDFLAGS variable. And the example doesn't work at all for the ScreenRewrite, needs to replace Screen with Scene etc.

+ Finally, in the example(s) a SceneLabel is attached to a Scene. The SceneLabel being allocated on the heap, but as the Scene does not own the SceneLabel we have to manually delete the SceneLabel, which seems kinda dumb. I would also generally try to keep the "new"'s within Polycode and let Polycode handle the memory to make it easier for the user.

I believe that's all I have to say for now. But if you agree with the smart pointer idea or the factory function I've got some things to start working on. As Polycode is quite messy in some places, and using smart ptrs and such would help greatly in making it cleaner internally, and hopefully externally later down the line.

Best regards, Jakob Larsson (Symphonym)