desktop icon indicating copy to clipboard operation
desktop copied to clipboard

Unknown function error for wxWebView.new when starting application on linux

Open adamwight opened this issue 3 years ago • 8 comments

I get a similar error with the desktop-example-app, and when following the instructions in "Your first Desktop App" to create a project from scratch,

** (Mix) Could not start application demo: Demo.Application.start(:normal, []) returned an error: shutdown: failed to start child: DemoWindow
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: {:error, {{:undefined_function, {:wxWebView, :new, 0}}, [{:wxe_util, :rec, 1, [file: 'wxe_util.erl', line: 110]}, {Desktop.Fallback, :webview_new, 1, [file: 'lib/desktop/fallback.ex', line: 51]}, {Desktop.Window, :init, 1, [file: 'lib/desktop/window.ex', line: 197]}, {:wx_object, :init_it, 6, [file: 'wx_object.erl', line: 404]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}}
            (desktop 1.4.1) lib/desktop/window.ex:105: Desktop.Window.start_link/1
            (stdlib 3.17.1) supervisor.erl:414: :supervisor.do_start_child_i/3
            (stdlib 3.17.1) supervisor.erl:400: :supervisor.do_start_child/2
            (stdlib 3.17.1) supervisor.erl:384: anonymous fn/3 in :supervisor.start_children/2
            (stdlib 3.17.1) supervisor.erl:1250: :supervisor.children_map/4
            (stdlib 3.17.1) supervisor.erl:350: :supervisor.init_children/2
            (stdlib 3.17.1) gen_server.erl:423: :gen_server.init_it/2
            (stdlib 3.17.1) gen_server.erl:390: :gen_server.init_it/6
            (stdlib 3.17.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

I've installed the dev libraries recommended in the linux installation notes, including libwxgtk-webview3.0-gtk3-dev.

adamwight avatar May 12 '22 07:05 adamwight

It lo like the version of erlang that you've installed has now wxWidgets installed. If your distribution has no way to install erlang including wxWidgets then

  1. try to get the erlang solutions distribution from: https://www.erlang-solutions.com/downloads/ or
  2. build from source

dominicletz avatar May 12 '22 09:05 dominicletz

I've tried both esl-erlang and the individual packages including erlang-wx, provided by erlang solutions. If I type :wx.new into an iex shell, I get {:wx_ref, 0, :wx, []} back which looks healthy.

# grep wx /usr/lib/erlang/releases/24/installed_application_versions 
wx-2.1.3

Stumbling in the dark for a bit, I tried to follow along with the wxErlang guide to set up, and then run a command similar to the one that fails at fallback.ex:47,

iex(1)> :wx.new()
Gtk-Message: 23:03:34.996: Failed to load module "canberra-gtk-module"
                                                                      {:wx_ref, 0, :wx, []}
iex(2)> win = :wxFrame.new(:wx.null(), 42, "Example", [])
{:wx_ref, 35, :wxFrame, []}
iex(3)> env = :wx.get_env()
{:wx_env, #Reference<0.1742318453.3220045825.244077>, #PID<0.108.0>, 0}
iex(4)> :wxWebView.new(win, -1)
** (ErlangError) Erlang error: {:undefined_function, {:wxWebView, :new, 0}}
    wxe_util.erl:110: :wxe_util.rec/1

I get the same error when trying to run other wxWebView functions, e.g. :wxWebView.isBackendAvailable('wxWebViewEdge'), so maybe this is specific to the webview module, or its backend. I'll play around some more to see what this is all about.

(Debian 11.3, OTP 24.3.3)

adamwight avatar May 12 '22 21:05 adamwight

You can try the :wx.demo() that should popup a window showing you all wxWidgets features available on your system. image

At the very bottom of the lefthand menu there should be wxWebView as in the picture. I'm not sure about debian, and how they compose the packages. Since a long time I've been only running builds from the official Erlang source code, so can't really tell what is in the distribution packages.

But elixir-desktop should probably provide a better error message on startup, so people know quickly what the problem is...

dominicletz avatar May 12 '22 22:05 dominicletz

Thanks for the :wx.demo() tip. Just to explore the distributed package, I compiled OTP but only copied over the compiled examples:

erl
1> filename:join([filename:dirname(code:priv_dir(wx)),examples,demo]).
"/usr/lib/erlang/lib/wx-2.1.3/examples/demo"
rsync -av ~/erlang-otp/lib/wx/examples /usr/lib/erlang/lib/wx-2.1.3/

Indeed, the application works but tells me "wxWebView support is missing in this installation". FWIW, the example code detects this situation simply by catching the undefined_function error in response to wxWebView:new.

I can build erlang-wx myself for now, but perhaps there should be an upstream request to include this part of the library by default.

As you said, the elixir-desktop code could convert the error to an actionable message. And I assume this will affect everyone using elixir-solutions.com packages on Linux, so maybe also worth mentioning in the setup docs here. From reading the lib/wx configure.in, I think that webview support isn't controlled by a flag, but automatically detected depending on whether the wx/webview.h header is available. So to include support, erlang-wx just needs to be compiled in an environment where the wx3.0-headers and maybe libwxgtk-webview3.0-gtk3-dev packages are installed.

adamwight avatar May 13 '22 05:05 adamwight

Good find I guess the issue is here in the esl builder not installing the webview components: https://github.com/esl/packages/blob/master/builders/erlang_debian.Dockerfile

dominicletz avatar May 13 '22 07:05 dominicletz

I'm experimenting with a more robust test for missing support, but I think I have to go a bit deeper into fallback.ex: https://github.com/adamwight/elixir-desktop/commit/34544b1b36986b48c54b3e21a406fc054d08a141

The issue is that, as the code is currently written webview?() needs to return false any time it's called, but we don't actually know about the incomplete support until the :wxWebView.new call fails. I'll try to make the module more assertive, it looks like these "if" statements can be replaced by a long "with" and slightly reorganized subroutines.

adamwight avatar May 13 '22 08:05 adamwight

+1 on this seeing similar results on macos. I'll try and post some more info this weekend.

thejohncotton avatar May 13 '22 20:05 thejohncotton

Hi, try this: https://github.com/asdf-vm/asdf-erlang/issues/244 check : wx-config --list output: Default config is gtk3-unicode-3.0 Default config will be used for output Alternate matches: base-unicode-3.0 gtk2-unicode-3.0

relax2code avatar Jun 23 '22 13:06 relax2code