Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak when destructing OpenGLBackend #9028

Closed
rubidium42 opened this issue Apr 12, 2021 · 2 comments
Closed

Memory leak when destructing OpenGLBackend #9028

rubidium42 opened this issue Apr 12, 2021 · 2 comments

Comments

@rubidium42
Copy link
Contributor

Version of OpenTTD

Anything at or after 436cdf1 (between 1.11.0-beta2 and 1.11.0-RC1)

Expected result

No memory leak (no definitely lost bytes in the leak summary)

Actual result

==27199== 24 bytes in 1 blocks are definitely lost in loss record 383 of 684
==27199== at 0x483877F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==27199== by 0xAECE1C: unsigned char* MallocT(unsigned long) (alloc_func.hpp:69)
==27199== by 0xAEC4C9: SimpleSpriteAlloc(unsigned long) (spritecache.cpp:819)
==27199== by 0x84FD6B: OpenGLBackend::Encode(SpriteLoader::Sprite const*, void* ()(unsigned long)) (opengl.cpp:1248)
==27199== by 0xAEBB2D: ReadSprite(SpriteCache const
, unsigned int, SpriteType, void* ()(unsigned long), SpriteEncoder) (spritecache.cpp:498)
==27199== by 0xAEC7CF: GetRawSprite(unsigned int, SpriteType, void* ()(unsigned long), SpriteEncoder) (spritecache.cpp:904)
==27199== by 0x84F710: OpenGLBackend::PopulateCursorCache() (opengl.cpp:1103)
==27199== by 0x8573C4: VideoDriver_SDL_OpenGL::PopulateSystemSprites() (sdl2_opengl_v.cpp:125)
==27199== by 0x858EBE: VideoDriver::Tick() (video_driver.cpp:175)
==27199== by 0x85605C: VideoDriver_SDL_Base::LoopOnce() (sdl2_v.cpp:642)
==27199== by 0x85609C: VideoDriver_SDL_Base::MainLoop() (sdl2_v.cpp:660)
==27199== by 0xA44F07: openttd_main(int, char**) (openttd.cpp:837)

Steps to reproduce

valgrind ./openttd -d sdl-opengl and then exiting the game.
Starting a game from the main menu doubles the loss and then exiting doubles the loss.

##Notes
#9027 solves some uninitialised memory issues that valgrind complains about.
The mentioned commit tries to fix a threading issue, but breaks this case. However, I am not sure whether calling the actual clearing logic in the destructor is safe for the threading issue solved in that commit.

@rubidium42 rubidium42 changed the title Memory when destructing OpenGLBackend Memory leak when destructing OpenGLBackend Apr 12, 2021
@nielsmh
Copy link
Contributor

nielsmh commented Apr 12, 2021

On the other hand, the game is exiting. The house is being torn down so why bother washing the floor?

@rubidium42
Copy link
Contributor Author

On the other hand, the game is exiting. The house is being torn down so why bother washing the floor?

The "exiting" the game is required as valgrind will only report errors once the application has stopped, so technically it does not tell you whether it leaked at the begin of just before the end.
Looking at the win32 video driver, whenever toggling full screen the OpenGLBackend is destroyed and thus the memory is leaked. Now it is a regression as it did not leak before.

Finally, the code bothers washing the floor; it requests the floor to be washed but then tears down the house before the floor washers can start their work.

michicc added a commit to michicc/OpenTTD that referenced this issue Apr 12, 2021
michicc added a commit to michicc/OpenTTD that referenced this issue Apr 12, 2021
LordAro pushed a commit to LordAro/OpenTTD that referenced this issue Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants