sony / flutter-embedded-linux

Embedded Linux embedding for Flutter
BSD 3-Clause "New" or "Revised" License
1.16k stars 122 forks source link

xdg_surface has never been configured #330

Closed SinkinZhu closed 1 year ago

SinkinZhu commented 1 year ago

Dear Sir

When we run our Flutter APP, it start failed, and show the error log : xdg_surface has never been configured Can you help me introduce how to debug this issue, Thanks

HidenoriMatsubayashi commented 1 year ago

What wayland compositor are you using?

Also, can you please share the whole log?

$ FLUTTER_LOG_LEVELS=TRACE ./flutter-client --bundle=<path_to_flutter_project_bundle>
makotosato-at commented 1 year ago

I got the same issue. This phenomenon also occurs in RPi4.

This phenomenon seems to occur under the following conditions:

  1. Using weston.
  2. Using video_player or/and camera plugin.
  3. Application is built in release mode.
  4. "$HOME/.cache/gstreamer-1.0/" directory does not exist.

If "$HOME/.cache/gstreamer-1.0/" exists, this phenomenon is not occur. "$HOME/.cache/gstreamer-1.0/" is created by _gstinit().

I don't know the detailed reasons, but it works fine when I try the following:

diff --git a/packages/camera/elinux/camera_elinux_plugin.cc b/packages/camera/elinux/camera_elinux_plugin.cc
index 4f841e0..c72f3dd 100644
--- a/packages/camera/elinux/camera_elinux_plugin.cc
+++ b/packages/camera/elinux/camera_elinux_plugin.cc
@@ -60,7 +60,6 @@ class CameraPlugin : public flutter::Plugin {
                flutter::TextureRegistrar* texture_registrar)
       : plugin_registrar_(plugin_registrar),
         texture_registrar_(texture_registrar) {
-    GstCamera::GstLibraryLoad();
   }
   virtual ~CameraPlugin() {
     if (camera_) {
diff --git a/packages/camera/elinux/gst_camera.cc b/packages/camera/elinux/gst_camera.cc
index 9bb0e47..0f383e8 100644
--- a/packages/camera/elinux/gst_camera.cc
+++ b/packages/camera/elinux/gst_camera.cc
@@ -8,6 +8,7 @@

 GstCamera::GstCamera(std::unique_ptr handler)
     : stream_handler_(std::move(handler)) {
+  gst_init(NULL, NULL);
   gst_.pipeline = nullptr;
   gst_.camerabin = nullptr;
   gst_.video_convert = nullptr;
diff --git a/packages/video_player/elinux/gst_video_player.cc b/packages/video_player/elinux/gst_video_player.cc
index 02339e8..f4433f7 100644
--- a/packages/video_player/elinux/gst_video_player.cc
+++ b/packages/video_player/elinux/gst_video_player.cc
@@ -9,6 +9,7 @@
 GstVideoPlayer::GstVideoPlayer(
     const std::string& uri, std::unique_ptr handler)
     : stream_handler_(std::move(handler)) {
+  gst_init(NULL, NULL); 
   gst_.pipeline = nullptr;
   gst_.playbin = nullptr;
   gst_.video_convert = nullptr;
diff --git a/packages/video_player/elinux/video_player_elinux_plugin.cc b/packages/video_player/elinux/video_player_elinux_plugin.cc
index a703e31..a41405a 100644
--- a/packages/video_player/elinux/video_player_elinux_plugin.cc
+++ b/packages/video_player/elinux/video_player_elinux_plugin.cc
@@ -58,9 +58,6 @@ class VideoPlayerPlugin : public flutter::Plugin {
                     flutter::TextureRegistrar* texture_registrar)
       : plugin_registrar_(plugin_registrar),
         texture_registrar_(texture_registrar) {
-    // Needs to call 'gst_init' that initializing the GStreamer library before
-    // using it.
-    GstVideoPlayer::GstLibraryLoad();
   }
   virtual ~VideoPlayerPlugin() {
     for (auto itr = players_.begin(); itr != players_.end(); itr++) {
HidenoriMatsubayashi commented 1 year ago

Ah, if we use camera and video plugins in a same app, it will lead double "gst_init(NULL, NULL)" call in the same app.

makotosato-at commented 1 year ago

Hello.

I could not get FLUTTER_LOG_LEVELS=TRACE log because it only occurs in the release version, but I could get WAYLAND_DEBUG=1 log instead.

flutter-elinux version is 3.3.10 and I got this log on RPi4. log.txt

HidenoriMatsubayashi commented 1 year ago

Thanks.

Did mouse cursor is enabled when the error happened? If so, can you please try again using --no-cursor option as a test?

makotosato-at commented 1 year ago

Did mouse cursor is enabled when the error happened? If so, can you please try again using --no-cursor option as a test?

I tried it and it didn't work. Again, I don't know why, but if $HOME/.cache/gstreamer-1.0 exists, it works fine. It doesn't seem to have anything to do with weston...

HidenoriMatsubayashi commented 1 year ago

Again, I don't know why, but if $HOME/.cache/gstreamer-1.0 exists, it works fine.

Strange. Does the issue happen even if using only video or camera plugin only?

makotosato-at commented 1 year ago

Strange. Does the issue happen even if using only video or camera plugin only?

Yes.

On my RPi4, if $HOME/.cache/gstreamer-1.0 is not exists, gst_init() takes about 1600ms to execute. If $HOME/.cache/gstreamer-1.0 exists, it takes 41ms.

This time may be causing the application initialization sequence to be incorrect.

As a test, sleep(1) instead of gst_init() also causes the phenomenon. video_player_elinux_plugin.cc:

  VideoPlayerPlugin(flutter::PluginRegistrar* plugin_registrar,
                    flutter::TextureRegistrar* texture_registrar)
      : plugin_registrar_(plugin_registrar),
        texture_registrar_(texture_registrar) {
    // Needs to call 'gst_init' that initializing the GStreamer library before
    // using it.
    //GstVideoPlayer::GstLibraryLoad();
    sleep(1);
  }
HidenoriMatsubayashi commented 1 year ago

I was not able to repro the issue. Can you please check if xdg_surface_ack_configure() is called before wl_surface_commit call?

See also: https://aznote.jakou.com/prog/wayland/06.html

makotosato-at commented 1 year ago

I was not able to repro the issue. Can you please check if xdg_surface_ack_configure() is called before wl_surface_commit call?

I attached a log (ng_log.txt) when the phenomenon occurs and a log (ok_log.txt) when it works correctly. It seems that xdg_surface_ack_configure is called after wl_surface_commit. ng_log.txt:

...
[4209127.458]  -> wl_surface@15.commit()
...
[4210790.425]  -> wl_surface@15.commit()
...
[4211134.920]  -> xdg_surface@17.ack_configure(205)
[4211135.022] wl_display@1.delete_id(24)
[4211135.061] wl_display@1.delete_id(26)
[4211135.094] wl_display@1.error(xdg_surface@17, 3, "xdg_surface has never been configured")
xdg_surface@17: error 3: xdg_surface has never been configured

ng_log.txt ok_log.txt

HidenoriMatsubayashi commented 1 year ago

@makotosato-at I'm not 100% sure, but can you please try https://github.com/sony/flutter-embedded-linux/pull/336 patch?

makotosato-at commented 1 year ago

Thank you for the patch. I tried but it didn't work.

HidenoriMatsubayashi commented 1 year ago

I've update the patch. Can you please try with it again? Also, please try flullscreen (-f) option and without its option.

makotosato-at commented 1 year ago

Thank you. It works fine!!

Also, please try flullscreen (-f) option and without its option.

Both ok.

HidenoriMatsubayashi commented 1 year ago

Thanks for helping to fix this issue.