fix memory leak for ProgramStateRegistry use

This commit is contained in:
halx99 2020-09-08 22:13:10 +08:00
parent 0141396fde
commit 1dd638535e
4 changed files with 6 additions and 4 deletions

View File

@ -150,7 +150,7 @@ bool DrawNode::init()
void DrawNode::updateShader()
{
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_COLOR_LENGTH_TEXTURE);
setProgramState(new (std::nothrow) backend::ProgramState(program));
attachProgramState(new (std::nothrow) backend::ProgramState(program));
_customCommand.getPipelineDescriptor().programState = _programState;
setVertexLayout(_customCommand);
_customCommand.setDrawType(CustomCommand::DrawType::ARRAY);

View File

@ -2131,7 +2131,9 @@ int Node::getAttachedNodeCount()
void Node::setProgramStateWithRegistry(backend::ProgramType programType, Texture2D* texture)
{
auto formatEXT = texture ? texture->getTextureFormatEXT() : 0;
setProgramState(backend::ProgramStateRegistry::getInstance()->getProgramState(programType, formatEXT));
auto programState = backend::ProgramStateRegistry::getInstance()->newProgramState(programType, formatEXT);
setProgramState(programState);
programState->release();
}
void Node::updateProgramStateTexture(Texture2D* texture)

View File

@ -43,7 +43,7 @@ void ProgramStateRegistry::clearPrograms() {
this->_registry.clear();
}
ProgramState* ProgramStateRegistry::getProgramState(ProgramType programType, int textureFormatEXT)
ProgramState* ProgramStateRegistry::newProgramState(ProgramType programType, int textureFormatEXT)
{
uint32_t key = (static_cast<uint32_t>(programType) << 16) | textureFormatEXT;
auto it = this->_registry.find(key);

View File

@ -41,7 +41,7 @@ public:
void registerProgram(ProgramType programType, int textureFormatEXT, Program*);
ProgramState* getProgramState(ProgramType programType, int textureFormatEXT);
ProgramState* newProgramState(ProgramType programType, int textureFormatEXT);
ProgramType getProgramType(ProgramType programType, int textureFormatEXT);
protected: