fix: prevent gc monitor 2nd pass crash (#46987)

This commit is contained in:
reito 2025-05-20 21:54:03 +08:00 committed by GitHub
commit 263c76df09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -143,19 +143,21 @@ v8::Local<v8::Value> Converter<electron::OffscreenSharedTextureValue>::ToV8(
// texture, output it in second pass callback. // texture, output it in second pass callback.
data.SetSecondPassCallback([](const v8::WeakCallbackInfo< data.SetSecondPassCallback([](const v8::WeakCallbackInfo<
OffscreenReleaseHolderMonitor>& data) { OffscreenReleaseHolderMonitor>& data) {
auto* iso = data.GetIsolate();
// Emit warning only once // Emit warning only once
static std::once_flag flag; static std::once_flag flag;
std::call_once(flag, [=] { std::call_once(flag, [=] {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce([] {
electron::util::EmitWarning( electron::util::EmitWarning(
iso, "Offscreen rendering shared texture was garbage "
"[OSR TEXTURE LEAKED] When using OSR with " "collected before calling `release()`. When using OSR "
"`useSharedTexture`, `texture.release()` " "with `useSharedTexture: true`, `texture.release()` "
"must be called explicitly as soon as the texture is " "must be called explicitly as soon as the texture is "
"copied to your rendering system. " "copied to your rendering system. Otherwise, it will "
"Otherwise, it will soon drain the underlying " "soon drain the underlying frame pool and prevent "
"framebuffer and prevent future frames from being generated.", "future frames from being sent.",
"SharedTextureOSRNotReleased"); "OSRSharedTextureNotReleased");
}));
}); });
}); });
} }