Skip to content

Commit 3c693c7

Browse files
Mee-guminggo
authored andcommitted
fix crash issue when egl context lost (#20025)
1 parent 28bc31a commit 3c693c7

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

cocos/renderer/backend/opengl/ProgramGL.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ ProgramGL::ProgramGL(const std::string& vertexShader, const std::string& fragmen
4343
std::string fsPreDefine("precision mediump float;\n precision mediump int;\n");
4444
vsPreDefine.append(vertexShader);
4545
fsPreDefine.append(fragmentShader);
46-
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(fsPreDefine));
47-
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(vsPreDefine));
46+
_vertexShader = std::move(vsPreDefine);
47+
_fragmentShader = std::move(fsPreDefine);
48+
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(_vertexShader));
49+
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(_fragmentShader));
4850
#else
4951
_vertexShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newVertexShaderModule(_vertexShader));
5052
_fragmentShaderModule = static_cast<ShaderModuleGL*>(ShaderCache::newFragmentShaderModule(_fragmentShader));
@@ -325,20 +327,16 @@ UniformLocation ProgramGL::getUniformLocation(backend::Uniform name) const
325327
UniformLocation ProgramGL::getUniformLocation(const std::string& uniform) const
326328
{
327329
UniformLocation uniformLocation;
328-
#if CC_ENABLE_CACHE_TEXTURE_DATA
329-
if (_originalUniformLocations.find(uniform) != _originalUniformLocations.end())
330-
{
331-
uniformLocation.location[0] = _originalUniformLocations.at(uniform);
332-
uniformLocation.location[1] = _activeUniformInfos.at(uniform).bufferOffset;
333-
}
334-
#else
335330
if (_activeUniformInfos.find(uniform) != _activeUniformInfos.end())
336331
{
337332
const auto& uniformInfo = _activeUniformInfos.at(uniform);
333+
#if CC_ENABLE_CACHE_TEXTURE_DATA
334+
uniformLocation.location[0] = _mapToOriginalLocation.at(uniformInfo.location);
335+
#else
338336
uniformLocation.location[0] = uniformInfo.location;
337+
#endif
339338
uniformLocation.location[1] = uniformInfo.bufferOffset;
340339
}
341-
#endif
342340
return uniformLocation;
343341
}
344342

0 commit comments

Comments
 (0)