Commit 0e8f7727 by Peng Huang Committed by Commit Bot

Fix crash in gl::Context::unMakeCurrent()

gl::Context's ctor may need to create a native EGL context and it can fail. If it fails, the context->mImplementation will be nullptr, and it will cause crash elsewhere. Fix the problem by checking it after create a gl::Context instance. Bug: chromium:1171371 Change-Id: Ic57f088dcbf9716b85fee92bf54d557eb94642d0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2686439Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Peng Huang <penghuang@chromium.org>
parent 6fc10389
......@@ -377,7 +377,14 @@ Context::Context(egl::Display *display,
ASSERT(mDisplay);
}
void Context::initialize()
egl::Error Context::initialize()
{
if (!mImplementation)
return egl::Error(EGL_NOT_INITIALIZED, "native context creation failed");
return egl::NoError();
}
void Context::initializeDefaultResources()
{
mImplementation->setMemoryProgramCache(mMemoryProgramCache);
......@@ -691,7 +698,7 @@ egl::Error Context::makeCurrent(egl::Display *display,
{
ASSERT(!mIsCurrent);
initialize();
initializeDefaultResources();
initRendererString();
initVersionStrings();
initExtensionStrings();
......
......@@ -353,6 +353,8 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
// Use for debugging.
ContextID id() const { return mState.getContextID(); }
egl::Error initialize();
egl::Error onDestroy(const egl::Display *display);
~Context() override;
......@@ -620,7 +622,7 @@ class Context final : public egl::LabeledObject, angle::NonCopyable, public angl
void dirtyAllState();
private:
void initialize();
void initializeDefaultResources();
angle::Result prepareForDraw(PrimitiveMode mode);
angle::Result prepareForClear(GLbitfield mask);
......
......@@ -1237,6 +1237,13 @@ Error Display::createContext(const Config *configuration,
gl::Context *context = new gl::Context(this, configuration, shareContext, shareTextures,
shareSemaphores, cachePointer, clientType, attribs,
mDisplayExtensions, GetClientExtensions());
Error error = context->initialize();
if (error.isError())
{
delete context;
return error;
}
if (shareContext != nullptr)
{
shareContext->setShared();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment