forked from ddnet/ddnet
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4989: Add null backend r=def- a=ChillerDragon Thanks to `@Jupeyy` for the idea. Replacing graphics_threaded_null.h with a null backend makes code maintenance and memory cleanup easier. Fixes these memory leaks in headless client (ddnet#4970) ``` Direct leak of 1048576 byte(s) in 1 object(s) allocated from: #0 0x4b6f6d in malloc (/home/runner/work/ddnet/ddnet/san/DDNet+0x4b6f6d) #1 0xd92ffb in CTextRender::InitTextures(int, int, IGraphics::CTextureHandle (&) [2], unsigned char* (&) [2]) /home/runner/work/ddnet/ddnet/src/engine/client/text.cpp:325:24 #2 0xd53795 in CTextRender::LoadFont(char const*, unsigned char const*, unsigned long) /home/runner/work/ddnet/ddnet/src/engine/client/text.cpp:729:3 #3 0xade5cd in CClient::LoadFont() /home/runner/work/ddnet/ddnet/src/engine/client/client.cpp:4070:32 #4 0x155b3de in CGameClient::OnInit() /home/runner/work/ddnet/ddnet/src/game/client/gameclient.cpp:246:12 #5 0xa8ecfe in CClient::Run() /home/runner/work/ddnet/ddnet/src/engine/client/client.cpp:2933:16 #6 0xaf6726 in main /home/runner/work/ddnet/ddnet/src/engine/client/client.cpp:4458:11 #7 0x7fadd9e610b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2) ``` ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [x] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: ChillerDrgon <ChillerDragon@gmail.com>
- Loading branch information
Showing
6 changed files
with
93 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "backend_null.h" | ||
|
||
bool CCommandProcessorFragment_Null::RunCommand(const CCommandBuffer::SCommand *pBaseCommand) | ||
{ | ||
switch(pBaseCommand->m_Cmd) | ||
{ | ||
case CCommandProcessorFragment_Null::CMD_INIT: | ||
Cmd_Init(static_cast<const SCommand_Init *>(pBaseCommand)); | ||
break; | ||
case CCommandBuffer::CMD_TEXTURE_CREATE: | ||
Cmd_Texture_Create(static_cast<const CCommandBuffer::SCommand_Texture_Create *>(pBaseCommand)); | ||
break; | ||
case CCommandBuffer::CMD_TEXT_TEXTURES_CREATE: | ||
Cmd_TextTextures_Create(static_cast<const CCommandBuffer::SCommand_TextTextures_Create *>(pBaseCommand)); | ||
break; | ||
case CCommandBuffer::CMD_TEXT_TEXTURE_UPDATE: | ||
Cmd_TextTexture_Update(static_cast<const CCommandBuffer::SCommand_TextTexture_Update *>(pBaseCommand)); | ||
break; | ||
} | ||
return true; | ||
} | ||
|
||
bool CCommandProcessorFragment_Null::Cmd_Init(const SCommand_Init *pCommand) | ||
{ | ||
pCommand->m_pCapabilities->m_TileBuffering = false; | ||
pCommand->m_pCapabilities->m_QuadBuffering = false; | ||
pCommand->m_pCapabilities->m_TextBuffering = false; | ||
pCommand->m_pCapabilities->m_QuadContainerBuffering = false; | ||
|
||
pCommand->m_pCapabilities->m_MipMapping = false; | ||
pCommand->m_pCapabilities->m_NPOTTextures = false; | ||
pCommand->m_pCapabilities->m_3DTextures = false; | ||
pCommand->m_pCapabilities->m_2DArrayTextures = false; | ||
pCommand->m_pCapabilities->m_2DArrayTexturesAsExtension = false; | ||
pCommand->m_pCapabilities->m_ShaderSupport = false; | ||
|
||
pCommand->m_pCapabilities->m_TrianglesAsQuads = false; | ||
|
||
pCommand->m_pCapabilities->m_ContextMajor = 0; | ||
pCommand->m_pCapabilities->m_ContextMinor = 0; | ||
pCommand->m_pCapabilities->m_ContextPatch = 0; | ||
return false; | ||
} | ||
|
||
void CCommandProcessorFragment_Null::Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand) | ||
{ | ||
free(pCommand->m_pData); | ||
} | ||
|
||
void CCommandProcessorFragment_Null::Cmd_TextTextures_Create(const CCommandBuffer::SCommand_TextTextures_Create *pCommand) | ||
{ | ||
free(pCommand->m_pTextData); | ||
free(pCommand->m_pTextOutlineData); | ||
} | ||
|
||
void CCommandProcessorFragment_Null::Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand) | ||
{ | ||
free(pCommand->m_pData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef ENGINE_CLIENT_BACKEND_NULL_BACKEND_NULL_H | ||
#define ENGINE_CLIENT_BACKEND_NULL_BACKEND_NULL_H | ||
|
||
#include <engine/client/backend/backend_base.h> | ||
|
||
class CCommandProcessorFragment_Null : public CCommandProcessorFragment_GLBase | ||
{ | ||
virtual bool GetPresentedImageData(uint32_t &Width, uint32_t &Height, uint32_t &Format, std::vector<uint8_t> &DstData) { return false; }; | ||
virtual bool RunCommand(const CCommandBuffer::SCommand *pBaseCommand); | ||
bool Cmd_Init(const SCommand_Init *pCommand); | ||
virtual void Cmd_Texture_Create(const CCommandBuffer::SCommand_Texture_Create *pCommand); | ||
virtual void Cmd_TextTextures_Create(const CCommandBuffer::SCommand_TextTextures_Create *pCommand); | ||
virtual void Cmd_TextTexture_Update(const CCommandBuffer::SCommand_TextTexture_Update *pCommand); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.