cginternals / globjects

C++ library strictly wrapping OpenGL objects.
https://globjects.org
MIT License
539 stars 59 forks source link

StateSetting leaking memory #328

Closed X-Ryl669 closed 7 years ago

X-Ryl669 commented 7 years ago

Or I'm unsure how to use it. I've this code:

auto currentState = globjects::State::currentState();
[...]
currentState->apply();
currentState->destroy(); // Tried with and without, same leak

got this:

=32073== 280 bytes in 5 blocks are definitely lost in loss record 76 of 124
==32073==    at 0x4C2A105: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==32073==    by 0x61B5DC: globjects::StateSetting::StateSetting<unsigned int>(void (*)(unsigned int), unsigned int) (in ~/Demo/Stitcher/build/Stitcher)
==32073==    by 0x619E85: globjects::AbstractState::primitiveRestartIndex(unsigned int) (in ~/Demo/Stitcher/build/Stitcher)
==32073==    by 0x62A6C9: globjects::State::currentState() (in ~/Demo/Stitcher/build/Stitcher)
==32073==    by 0x5B81B1: Stitcher::Application::Impl::fetchSources() (Application.cpp:275)
==32073==    by 0x5B2C52: Stitcher::Application::runLoop() (Application.cpp:415)
==32073==    by 0x5AEBD3: main (main.cpp:114)
==32073== 

I'm doing this for each frame, and it's a pain.

As a side note, all the sample code on the main page says use the auto var = new XXX pattern without saying why and what is supposed to be used inside a class member. I think you should emphasize to use ref_ptr<T> instead, since the former leaks (auto is mapped to XXX * not ref_ptr<XXX> in that case)

scheibel commented 7 years ago

Thanks for reporting. I provided a fix in the master branch.

Regarding your suggestion I think we should revise the examples in the README.md. I'll open a separate issue for that.