8000 fix: prevent crash when GPU context unavailable in sharedTexture by ianwith · Pull Request #49518 · electron/electron · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@ianwith
Copy link
@ianwith ianwith commented Jan 24, 2026

Description of Change

This PR fixes a critical crash in the sharedTexture (introduced in #47317) module related to improper lifecycle management of the graphics context provider.

The crash happens in the ImportedSharedTexture destructor when it calls SetupReleaseSyncTokenCallback(), which in turn calls GetContextSupport(). In renderer processes, GetContextSupport() attempts to dereference a WeakPtr<blink::WebGraphicsContext3DProviderWrapper> without first checking if the pointer is valid. When the GPU context is unavailable (e.g., during shutdown or GPU device loss), this WeakPtr is null, causing a CHECK failure.

The fix introduces a safety check in GetContextSupport() to verify the availability of the context provider before usage. Additionally, the destruction sequence has been updated to handle context loss gracefully, preventing the EXCEPTION_BREAKPOINT triggered by base::WeakPtr's internal checks.

Stack Trace Included:
1

#0 main.dll!base::ImmediateCrash()
#1 main.dll!logging::CheckFailure()
#2 main.dll!base::WeakPtr<...>::operator->()
#3 main.dll!(anonymous namespace)::GetContextSupport()
#4 main.dll!(anonymous namespace)::ImportedSharedTexture::SetupReleaseSyncTokenCallback()
#5 main.dll!(anonymous namespace)::ImportedSharedTexture::~ImportedSharedTexture()

2

#0 main.dll!media::mp2t::Mp2tStreamParser::GetDecryptConfig()
#1 main.dll!(anonymous namespace)::GetSharedImageInterface()
#2 main.dll!electron::api::shared_texture::ImportSharedTexture()

Checklist

Release Notes

Notes: Fixed crash in sharedTexture module when GPU context becomes unavailable.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jan 24, 2026
Copy link
Member
@codebytere codebytere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to log on every line here.

Comment on lines 92 to 119
F440
if (!factory) {
LOG(ERROR) << "ImageTransportFactory is null";
return nullptr;
}

auto* context_factory = factory->GetContextFactory();
if (!context_factory) {
LOG(ERROR) << "ContextFactory is null";
return nullptr;
}

scoped_refptr<viz::RasterContextProvider> provider =
context_factory->SharedMainThreadRasterContextProvider();
if (!provider) {
LOG(ERROR) << "RasterContextProvider is null";
return nullptr;
}

return provider->SharedImageInterface();
} else {
return blink::SharedGpuContext::SharedImageInterfaceProvider()
->SharedImageInterface();
auto* provider = blink::SharedGpuContext::SharedImageInterfaceProvider();
if (!provider) {
LOG(ERROR)
<< "SharedImageInterfaceProvider is null, GPU context unavailable";
return nullptr;
}

return provider->SharedImageInterface();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same like above.


std::string GetBase64StringFromSyncToken(gpu::SyncToken& sync_token) {
if (!sync_token.verified_flush()) {
auto* sii = GetSharedImageInterface();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of logging and silently return, is it possible to pass sii and context support as parameter in, instead of GetShareImageInterface, GetContextSupport in place? Then we can do checks earlier in outer entry functions with throwable javascript error.

// Texture id for printing warnings like GC check.
std::string id;

Copy link
Member
@reitowo reitowo Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove spaces (You might want to run npm run lint to find lint errors locally before failing the CI)

Comment on lines 366 to 371
if (!sii) {
LOG(WARNING)
<< "Cannot update release sync token, SharedImageInterface is null";
return;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, can we pass sii in?

base::AutoLock locker(release_sync_token_lock_);

auto* sii = GetSharedImageInterface();
if (!sii) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

if (release_callback) {
GetContextSupport()->SignalSyncToken(release_sync_token,
std::move(release_callback));
auto* context_support = GetContextSupport();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@reitowo
Copy link
Member
reitowo commented Jan 25, 2026

Thanks for fixing this!

ianwith and others added 2 commits January 26, 2026 14:17
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Comment on lines 81 to 99
if (!factory) {
LOG(ERROR) << "ImageTransportFactory is null";
return nullptr;
}

auto* context_factory = factory->GetContextFactory();
if (!context_factory) {
LOG(ERROR) << "ContextFactory is null";
return nullptr;
}

scoped_refptr<viz::RasterContextProvider> provider =
context_factory->SharedMainThreadRasterContextProvider();
if (!provider) {
LOG(ERROR) << "RasterContextProvider is null";
return nullptr;
}

return provider->SharedImageInterface();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same logging comments here as above

@ianwith ianwith force-pushed the import-shared-texture-updates branch from 95b0bff to 8f73cfd Compare January 28, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-pr 🌱 PR opened recently

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0