Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaPlayerElement created from C++/WinRT crashes when AreTransportControlsEnabled is set to true #9265

Closed
Tracked by #1
kasperisager opened this issue Jan 19, 2024 · 5 comments
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@kasperisager
Copy link

kasperisager commented Jan 19, 2024

Describe the bug

Consider the following C++ application:

struct App : public ApplicationT<App> {
  void
  OnLaunched (LaunchActivatedEventArgs const &) {
    MediaPlayerElement player;
    player.AreTransportControlsEnabled(true);

    Window window;
    window.Content(player);
    window.Activate();
  }
};

int
main () {
  init_apartment();

  Application::Start([] (auto &&) { make<App>(); });
}

For some reason, the above application immediately crashes with the following error:

HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) : The data area passed to a system call is too small.

If I remove player.AreTransportControlsEnabled(true) it doesn't crash, but I also don't get any transport controls.

Steps to reproduce the bug

  1. Compile and run the code above.

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.4.4: 1.4.231219000

Windows version

Windows 11 (22H2): Build 22621

Additional context

If relevant, this is the manifest used:

<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity name="App" version="1.0.0.0" />

  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
    </windowsSettings>
  </application>

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <maxversiontested Id="10.0.18362.1"/>
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
    </application>
  </compatibility>
</assembly>
@kasperisager kasperisager added the bug Something isn't working label Jan 19, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jan 19, 2024
@DarranRowe
Copy link

Does it work if you set AreTransportControlsEnabled to true after you set the MediaPlayerElement as the content of the window?
What about if you use a container control as a container for the MediaPlayerElement? So have the window's content be a Grid or a StackPanel, and then this Grid or StackPanel contains the MediaPlayerElement.

@kasperisager
Copy link
Author

@DarranRowe Thanks for the suggestions! All of these also cause a crash unfortunately:

MediaPlayerElement player;

Window window;
window.Content(player);

player.AreTransportControlsEnabled(true);

window.Activate();
MediaPlayerElement player;
player.AreTransportControlsEnabled(true);

Grid grid;
grid.Children().Append(player);

Window window;
window.Content(grid);
window.Activate();
MediaPlayerElement player;
player.AreTransportControlsEnabled(true);

StackPanel panel;
panel.Children().Append(player);

Window window;
window.Content(panel);
window.Activate();

@DarranRowe
Copy link

DarranRowe commented Jan 20, 2024

Just to be sure, is your App definition a properly defined App with the metadata being generated by the Xaml compiler?

--Edit--
Yeah.

Screenshot 2024-01-20 190524

A properly set up project works. I suspect that you are not implementing IXamlMetadataProvider in App. You would either need to manually implement it as an extra interface, or enable the Xaml compiler in your project.
The Xaml Islands sample should provide enough information to do this. But this doesn't mean that you have to go all in with the Xaml Islands. You should be able to use Application.Start like you are currently doing.
If you are using the Xaml compiler, the two real things you should do is set the ApplicationType element to Windows Store in the .vcxproj and set the App.xaml file to ApplicationDefinition.

@kasperisager
Copy link
Author

@DarranRowe Implementing IXamlMetadataProvider and adding the default XAML controls resources did the trick, thanks so much! Is this documented somewhere?

For reference, this is the adjusted App implementation:

struct App : public ApplicationT<App, IXamlMetadataProvider> {
  void
  OnLaunched (LaunchActivatedEventArgs const &) {
    Resources().MergedDictionaries().Append(XamlControlsResources());

    MediaPlayerElement player;
    player.AreTransportControlsEnabled(true);

    Window window;
    window.Content(player);
    window.Activate();
  }

  XamlControlsXamlMetaDataProvider provider;

  IXamlType
  GetXamlType (hstring const &name) {
    return provider.GetXamlType(name);
  }

  IXamlType
  GetXamlType (TypeName const &type) {
    return provider.GetXamlType(type);
  }

  com_array<XmlnsDefinition>
  GetXmlnsDefinitions () {
    return provider.GetXmlnsDefinitions();
  }
};

As an addendum, I'm working on a cross-platform GUI library built and consumed using CMake, hence why I want to stick to plain C++. It's not that I don't think XAML is a worthwhile technology, I simply don't want to push additional build tooling requirements to downstream consumers.

Thanks again!

@microsoft-github-policy-service microsoft-github-policy-service bot added needs-triage Issue needs to be triaged by the area owners and removed needs-triage Issue needs to be triaged by the area owners labels Jan 21, 2024
@DarranRowe
Copy link

Yes. The unfortunate thing is that it is documented in the IXamlType documentation. There is a brief explanation in IXamlMetadataProvider too. The issue is that you have to know about this to find the documentation. It would be nice if this was mentioned in the Application documentation.

The other big issue is that the exact requirements are not fully documented. The application's side of the generated code is fully visible though.

Screenshot 2024-01-22 105809
Screenshot 2024-01-22 105814

So it is possible to figure it out from this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

2 participants