StereoKit: HoloLens graphics crash

Description

From Christoph on Discord:

Recently encountered this weird error when starting the app. Any idea what could cause this? It happens very rarely but always appears right after starting the app and when SK is already running. It seems like the frames don’t get cleared but just draw on top of each other. We are running some asynchronous code (specifically request permissions https://learn.microsoft.com/hu-hu/uwp/api/windows.security.authorization.appcapabilityaccess.appcapability.requestaccessforcapabilitiesasync?view=winrt-22621&viewFallbackFrom=winrt-14393) between SK.Initialize and SK.Run, could this have anything to do with it? Possibly looks related to this issue: https://github.com/StereoKit/StereoKit/issues/361

bug_multiple

Platform / Environment

UWP/HoloLens 2

Logs or exception details

Here’s some abbreviated logs

[SK info] [RequestAccess::GetNativeCapabilities] Requesting eye gaze permission.
[SK info] [RequestAccess::GetNativeCapabilities] Requesting webcam permission.
[SK info] [RequestAccess::GetNativeCapabilities] Requesting microphone permission.
[SK info] [RequestAccess::GetInternalCapabilities] Requesting qr code permission.
[SK info] [RequestAccess::GetInternalCapabilities] Requesting research mode permission.
[SK info] [RequestAccess::GetCapabilites] All native capabilities passed: True.
[SK info] [RequestAccess::GetCapabilites] All internal capabilities passed: True.
[SK error] sk_gpu: CreateBuffer failed!
[SK error] sk_gpu: Create texture error!
[SK error] mesh_set_inds: Failed to create dynamic index buffer
[SK error] sk_gpu: Create Shader Resource View error!
[SK error] sk_gpu: CreateBuffer failed!
[SK error] mesh_set_verts: Failed to create dynamic vertex buffer
[SK error] sk_gpu: CreateBuffer failed!
[SK error] mesh_set_verts: Failed to create vertex buffer
[SK error] sk_gpu: CreateBuffer failed!
[SK error] mesh_set_verts: Failed to create vertex buffer
[SK error] sk_gpu: CreateBuffer failed!
[SK error] mesh_set_verts: Failed to create vertex buffer

And pseudocode for the application flow

static void Main(string[] args)
{
    SKSettings settings = new()
    {
        appName = applicationName,
        assetsFolder = "Assets",
    };
    Task someTask = doSomeTask();

    if (!SK.Initialize(settings))
        Environment.Exit(1);
    
    Action onComplete = async () =>
    {
        await someTask;
        SK.AddStepper<Menu>();
    };

    RequestAccess access = new(onComplete);
    SK.AddStepper(access);

    SK.Run();
}

class RequestAccess : IStepper
{
    private Action onComplete;
    RequestAccess(Action onComplete)
    {
        this.onComplete ??= onComplete;
    }

    public void Step()
    {
        switch (State)
        {
            case MenuState.RequestCapabilities:
                State = MenuState.RequestingCapabilities;
                // Run the async task without await so that it runs on another worker thread, separate from
                // the SK initialization/stepper thread (which has async Asset creation in https://github.com/StereoKit/StereoKit/issues/361)
                _ = this.GetCapabilites(); // run async task
                break;
            case MenuState.RequestingCapabilities:
                break; // do nothing
            case MenuState.PermissionsMenu:
                this.PermissionsMenu(); // show missing permissions UI
                break;
            case MenuState.Shutdown:
                SK.RemoveStepper(this);
                this.onComplete?.Invoke(); // add other steppers
                break;
        }
    }
}

class Menu : IStepper
{
    bool Initialize()
    {
        someSprite = Sprite.FromFile("some.png", SpriteType.Single);
        return true;
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 39 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, these errors look like something I can dig into, I think this is what I was hoping to get from that build!

This is actually the first time I’ve ever seen D3D unhappy with multithreading! SK’s asset thread has been tossing stuff at the GPU thread for a while now, and I haven’t ever seen this issue on PC. I wonder if it’s a difference in drivers on HoloLens?

Either way, I’ll try saturating this path and see if I can repro it. The debug message alone gives me a fair bit I can read up on, thanks a bunch for this!

I’ve done a good bit of work to make sure that asset creation should be safe to call from any thread. There may be some edge cases lingering around here, but I haven’t observed any myself for a long while now! I probably need to make a better suite of tests related to this though, I don’t have a lot of async code in the current test code.

Drawing, UI, and hierarchy code should all be on the main thread, I haven’t looked at those from a multi-threaded lens yet.

If you call an async method from the Step method, does this mean that the game thread can go into the async method?

I haven’t ever observed this happening or causing problems! But now that you mention it, I should probably figure out why I haven’t seen it causing problems, or verify that for sure.