From ced7f2889861c143122ec2d9bbed2a2d3a756ecf Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 2 Jul 2026 14:37:29 +0800 Subject: [PATCH] [Fix] (MG_Impl/GLImpl, MG_State/GLState): reject unlinked empty programs [skip ci] --- MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp | 7 +++++++ MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp b/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp index 9c66ee06..a5d3a6c4 100644 --- a/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp +++ b/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp @@ -624,6 +624,13 @@ namespace MobileGL::MG_Impl::GLImpl { auto& programObject = TryToGetProgramObject(program); if (!programObject) return; + if (!programObject->GetLinkStatus()) { + MG_State::pGLContext->RecordError( + ErrorCode::InvalidOperation, + MakeUnique("MG_Impl/GLImpl", __func__, + "program " + std::to_string(program) + " is not linked.")); + return; + } MG_State::pGLContext->UseProgram(program); } diff --git a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp index f1a9e16c..a67c82c5 100644 --- a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp +++ b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp @@ -171,6 +171,11 @@ namespace MobileGL::MG_State::GLState { if (addDefaultFSIfMissingForRenderingPipelineProgram) { AddDefaultFragmentShaderIfMissing(); } + if (m_shaders.empty()) { + m_infoLog = "No shader objects are attached to program."; + MGLOG_E("ProgramObject %u: Link failed - no shader objects attached.", m_externalIndex); + return; + } std::sort(m_shaders.begin(), m_shaders.end(), [](const SharedPtr& a, const SharedPtr& b) {