Closed Bug 1276931 Opened 8 years ago Closed 8 years ago

gfxPlatform::Init can be called from the vblankloop

Categories

(Core :: Graphics, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla50
Tracking Status
firefox47 --- affected
firefox48 --- fixed
firefox49 --- fixed
firefox-esr45 --- affected
firefox50 --- fixed

People

(Reporter: jdm, Assigned: mchang)

References

Details

(Whiteboard: gfx-noted)

Crash Data

Attachments

(1 file, 3 obsolete files)

We should be able to make sure we call Init() before starting the vsync thread.
Assignee: nobody → mchang
(In reply to Jeff Muizelaar [:jrmuizel] from comment #1)
> We should be able to make sure we call Init() before starting the vsync
> thread.

The only way we start the vsync thread is during gfxWindowsPlatform::Init. This seems to be happening during shutdown where we're calling the gfxWindowsPlatform during vsync shutdown.
Whiteboard: gfx-noted
(In reply to Mason Chang [:mchang] from comment #3)
> The only way we start the vsync thread is during gfxWindowsPlatform::Init.
> This seems to be happening during shutdown where we're calling the
> gfxWindowsPlatform during vsync shutdown.

Fun.
We should probably set gPlatform to something like 0x1 so that we don't try to reinitialize and crash instead.
I think what's happening here is that we shutdown gfxPlatform and don't wait to ensure that vsync is actually shutdown yet. Normally, the destructor for Vsync will stop the vsync thread during clean up. However, the destructor hasn't run yet and instead the vblank loop is going on the vsync thread at the same time the main thread shut down the gfxPlatform. This was fine until bug 1256547, which added calls to fetch gfxPlatform during each vblank loop. This patch disables vsync on the main thread during gfxPlatform::Shutdown.
Attachment #8758422 - Flags: review?(jmuizelaar)
Attachment #8758422 - Attachment is obsolete: true
Attachment #8758422 - Flags: review?(jmuizelaar)
Attachment #8758423 - Flags: review?(jmuizelaar)
Comment on attachment 8758423 [details] [diff] [review]
Disable vsync before clearing VsyncSource

Review of attachment 8758423 [details] [diff] [review]:
-----------------------------------------------------------------

::: gfx/thebes/gfxPlatform.cpp
@@ +822,5 @@
> +    gPlatform->mMemoryPressureObserver = nullptr;
> +    gPlatform->mSkiaGlue = nullptr;
> +
> +    if (XRE_IsParentProcess()) {
> +      gPlatform->mVsyncSource->GetGlobalDisplay().DisableVsync();

Shouldn't this wait until the vsync thread dies?
(In reply to Jeff Muizelaar [:jrmuizel] from comment #8)
> Comment on attachment 8758423 [details] [diff] [review]
> Disable vsync before clearing VsyncSource
> 
> Review of attachment 8758423 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: gfx/thebes/gfxPlatform.cpp
> @@ +822,5 @@
> > +    gPlatform->mMemoryPressureObserver = nullptr;
> > +    gPlatform->mSkiaGlue = nullptr;
> > +
> > +    if (XRE_IsParentProcess()) {
> > +      gPlatform->mVsyncSource->GetGlobalDisplay().DisableVsync();
> 
> Shouldn't this wait until the vsync thread dies?

That only happens during destruction since we want to reuse the thread normally. Since we're in shutdown, nothing should be enabling vsync again, so that should stop this crash as the thread will just be idle.
(In reply to Mason Chang [:mchang] from comment #9)
> (In reply to Jeff Muizelaar [:jrmuizel] from comment #8)
> > Comment on attachment 8758423 [details] [diff] [review]
> > Disable vsync before clearing VsyncSource
> > 
> > Review of attachment 8758423 [details] [diff] [review]:
> > -----------------------------------------------------------------
> > 
> > ::: gfx/thebes/gfxPlatform.cpp
> > @@ +822,5 @@
> > > +    gPlatform->mMemoryPressureObserver = nullptr;
> > > +    gPlatform->mSkiaGlue = nullptr;
> > > +
> > > +    if (XRE_IsParentProcess()) {
> > > +      gPlatform->mVsyncSource->GetGlobalDisplay().DisableVsync();
> > 
> > Shouldn't this wait until the vsync thread dies?
> 
> That only happens during destruction since we want to reuse the thread
> normally. Since we're in shutdown, nothing should be enabling vsync again,
> so that should stop this crash as the thread will just be idle.

I don't understand what prevents us from deleteing gPlatform before the last call to GetPlatform() at https://hg.mozilla.org/releases/mozilla-beta/annotate/0723a0212f5e/gfx/thebes/gfxWindowsPlatform.cpp#l2824
?
(In reply to Jeff Muizelaar [:jrmuizel] from comment #10)
> (In reply to Mason Chang [:mchang] from comment #9)
> > (In reply to Jeff Muizelaar [:jrmuizel] from comment #8)
> > > Comment on attachment 8758423 [details] [diff] [review]
> > > Disable vsync before clearing VsyncSource
> > > 
> > > Review of attachment 8758423 [details] [diff] [review]:
> > > -----------------------------------------------------------------
> > > 
> > > ::: gfx/thebes/gfxPlatform.cpp
> > > @@ +822,5 @@
> > > > +    gPlatform->mMemoryPressureObserver = nullptr;
> > > > +    gPlatform->mSkiaGlue = nullptr;
> > > > +
> > > > +    if (XRE_IsParentProcess()) {
> > > > +      gPlatform->mVsyncSource->GetGlobalDisplay().DisableVsync();
> > > 
> > > Shouldn't this wait until the vsync thread dies?
> > 
> > That only happens during destruction since we want to reuse the thread
> > normally. Since we're in shutdown, nothing should be enabling vsync again,
> > so that should stop this crash as the thread will just be idle.
> 
> I don't understand what prevents us from deleteing gPlatform before the last
> call to GetPlatform() at
> https://hg.mozilla.org/releases/mozilla-beta/annotate/0723a0212f5e/gfx/
> thebes/gfxWindowsPlatform.cpp#l2824
> ?

If we call DisableVsync before, that loop should exit here - https://hg.mozilla.org/releases/mozilla-beta/annotate/0723a0212f5e/gfx/thebes/gfxWindowsPlatform.cpp#l2812
(In reply to Mason Chang [:mchang] from comment #11)
> If we call DisableVsync before, that loop should exit here -
> https://hg.mozilla.org/releases/mozilla-beta/annotate/0723a0212f5e/gfx/
> thebes/gfxWindowsPlatform.cpp#l2812

It seems like this can still race. If we begin the vsync loop just before and then shutdown code runs.
(In reply to Jeff Muizelaar [:jrmuizel] from comment #12)
> (In reply to Mason Chang [:mchang] from comment #11)
> > If we call DisableVsync before, that loop should exit here -
> > https://hg.mozilla.org/releases/mozilla-beta/annotate/0723a0212f5e/gfx/
> > thebes/gfxWindowsPlatform.cpp#l2812
> 
> It seems like this can still race. If we begin the vsync loop just before
> and then shutdown code runs.

But gPlatform will still exist since we don't null it out until gfxPlatform::Shutdown ends - https://dxr.mozilla.org/mozilla-central/source/gfx/thebes/gfxPlatform.cpp?from=gfxPlatform.cpp#860

Or we can stop referencing gfxPlatform in the vblank loop?
Comment on attachment 8758423 [details] [diff] [review]
Disable vsync before clearing VsyncSource

Review of attachment 8758423 [details] [diff] [review]:
-----------------------------------------------------------------

Let's just shutdown and wait for the thread to finish.
Attachment #8758423 - Flags: review?(jmuizelaar) → review-
Attached patch Add VsyncSource::Shutdown (obsolete) — Splinter Review
Adds a VsyncSource::Shutdown which shutsdown the global display. Each global display::shutdown is the destructor code.
Attachment #8758423 - Attachment is obsolete: true
Attachment #8758894 - Flags: review?(jmuizelaar)
Attachment #8758894 - Flags: review?(jmuizelaar) → review+
Had to fix a few try errors due to typos, but try looks good now - https://hg.mozilla.org/try/rev/b7ce4d3d8efb9bfc9c2a4502c0fc8b0acb424e9c
Pushed by mchang@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/c82675873549
Add VsyncSource::Shutdown which shuts down global display. r=jrmuizel
Attachment #8758894 - Attachment is obsolete: true
Attachment #8760513 - Flags: review+
https://hg.mozilla.org/mozilla-central/rev/c82675873549
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
Comment on attachment 8760513 [details] [diff] [review]
Add VsyncSource::Shutdown

Approval Request Comment
[Feature/regressing bug #]: Bug 1256547
[User impact if declined]: User can have a shutdown crash
[Describe test coverage new/current, TreeHerder]: Try
[Risks and why]: Low, this just cleans up the vsync work a bit earlier.
[String/UUID change made/needed]: None
Attachment #8760513 - Flags: approval-mozilla-beta?
Attachment #8760513 - Flags: approval-mozilla-aurora?
Blocks: 1256547
Comment on attachment 8760513 [details] [diff] [review]
Add VsyncSource::Shutdown

Fix a shutdown crash, taking it.
Attachment #8760513 - Flags: approval-mozilla-beta?
Attachment #8760513 - Flags: approval-mozilla-beta+
Attachment #8760513 - Flags: approval-mozilla-aurora?
Attachment #8760513 - Flags: approval-mozilla-aurora+
Crash volume for signature 'gfxPlatform::Init':
 - nightly(version 50):2 crashes from 2016-06-06.
 - aurora (version 49):6 crashes from 2016-06-07.
 - beta   (version 48):286 crashes from 2016-06-06.
 - release(version 47):5969 crashes from 2016-05-31.
 - esr    (version 45):1 crash from 2016-04-07.

Crash volume on the last weeks:
            W. N-1  W. N-2  W. N-3  W. N-4  W. N-5  W. N-6  W. N-7
 - nightly       0       0       0       0       0       0       0
 - aurora        0       0       0       0       0       0       4
 - beta          1       1       2       2      13      99     131
 - release     369     428     922     989    1064    1001     983
 - esr           0       0       0       0       0       0       0

Affected platforms: Windows, Linux
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: