Bug 244464 - math/wxmaxima doesn't launch
Summary: math/wxmaxima doesn't launch
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Lorenzo Salvadore
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-27 07:40 UTC by Peter Kien
Modified: 2020-03-13 12:35 UTC (History)
4 users (show)

See Also:
salvadore: maintainer-feedback+


Attachments
wxmaxima - bugfix (1.90 KB, patch)
2020-03-10 09:44 UTC, Lorenzo Salvadore
salvadore: maintainer-approval+
Details | Diff
wxmaxima - bugfix - v2 (1.45 KB, patch)
2020-03-11 14:44 UTC, Lorenzo Salvadore
salvadore: maintainer-approval+
Details | Diff
testfile for wx paths (2.52 KB, text/plain)
2020-03-11 17:17 UTC, Loïc Bartoletti
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Kien 2020-02-27 07:40:00 UTC
The program segfaults on launch, complaining that:

/usr/local/include/wx-3.0/wx/arrstr.h(191): assert "!IsEmpty()" failed in Last(): wxArrayString: index out of bounds

(process:66957): Gtk-CRITICAL **: 07:38:16.234: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:66957): Gtk-CRITICAL **: 07:38:16.235: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:66957): Gtk-CRITICAL **: 07:38:16.235: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed
Comment 1 Lorenzo Salvadore freebsd_committer 2020-02-27 11:22:10 UTC
I am investigating on it.
I have almost ready a patch for latest version which containts many (unspecified) bug fixes: we could maybe try to see if it solves that particular bug.

In the meantime I am building wxmaxima on my system to see if I can reproduce your issue.
Comment 2 Lorenzo Salvadore freebsd_committer 2020-02-27 12:24:42 UTC
I have just committed the update to wxmaxima. Unfortunately I remembered wrong and it does not contain many fixes, but only two deadlocks fixes. Still, could you test the new wxmaxima version and tell if the problem is still present?

Unfortunately at the moment I am unable to attempt to reproduce your issue: I am on CURRENT and a dependency is affected by bug #244469. I won't be able to go further until it is fixed.
If anyone could confirm that the bug is indeed reproducible it could be useful.
Comment 3 Lorenzo Salvadore freebsd_committer 2020-02-27 22:11:36 UTC
I have successfully reproduced your bug on 13.0-CURRENT r358179.
Now I am working to fix it.
Comment 4 commit-hook freebsd_committer 2020-03-03 00:46:01 UTC
A commit references this bug:

Author: salvadore
Date: Tue Mar  3 00:45:16 UTC 2020
New revision: 527659
URL: https://svnweb.freebsd.org/changeset/ports/527659

Log:
  Add debug support for math/wxmaxima

  PR:		244464
  Approved by:	gerald (mentor)

Changes:
  head/math/wxmaxima/Makefile
Comment 5 Kevin Zheng 2020-03-03 06:01:24 UTC
I am also affected by this issue. I do not have debugging symbols enabled, but I have this (not so useful) backtrace on 12.1-RELEASE-p2 on amd64:

Starting program: /usr/local/bin/wxmaxima 
/usr/local/include/wx-3.0/wx/arrstr.h(191): assert "!IsEmpty()" failed in Last(): wxArrayString: index out of bounds

(process:78693): Gtk-CRITICAL **: 22:00:14.840: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:78693): Gtk-CRITICAL **: 22:00:14.841: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:78693): Gtk-CRITICAL **: 22:00:14.841: _gtk_style_provider_private_get_settings: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

Program received signal SIGSEGV, Segmentation fault.
0x000000080219ef64 in ?? () from /usr/local/lib/libgtk-3.so.0
(gdb) bt
#0  0x000000080219ef64 in  () at /usr/local/lib/libgtk-3.so.0
#1  0x00000008020343b2 in  () at /usr/local/lib/libgtk-3.so.0
#2  0x00000008020567c7 in  () at /usr/local/lib/libgtk-3.so.0
#3  0x000000080203fe3b in  () at /usr/local/lib/libgtk-3.so.0
#4  0x00000008020566fd in  () at /usr/local/lib/libgtk-3.so.0
#5  0x00000008020565d7 in  () at /usr/local/lib/libgtk-3.so.0
#6  0x0000000802040b27 in  () at /usr/local/lib/libgtk-3.so.0
#7  0x0000000802662cb6 in g_type_create_instance () at /usr/local/lib/libgobject-2.0.so.0
#8  0x0000000802650295 in  () at /usr/local/lib/libgobject-2.0.so.0
#9  0x000000080264facc in g_object_new () at /usr/local/lib/libgobject-2.0.so.0
#10 0x000000080205e928 in  () at /usr/local/lib/libgtk-3.so.0
#11 0x00000008022618e2 in  () at /usr/local/lib/libgtk-3.so.0
#12 0x0000000802662cb6 in g_type_create_instance () at /usr/local/lib/libgobject-2.0.so.0
#13 0x0000000802650295 in  () at /usr/local/lib/libgobject-2.0.so.0
#14 0x000000080264facc in g_object_new () at /usr/local/lib/libgobject-2.0.so.0
#15 0x0000000800d46429 in  () at /usr/local/lib/libwx_gtk3u_core-3.0.so.0
#16 0x0000000800d715b6 in wxGUIAppTraits::ShowAssertDialog(wxString const&) () at /usr/local/lib/libwx_gtk3u_core-3.0.so.0
#17 0x0000000800789220 in  () at /usr/local/lib/libwx_baseu-3.0.so.0
#18 0x0000000800788a0b in wxAppConsoleBase::OnAssertFailure(wchar_t const*, int, wchar_t const*, wchar_t const*, wchar_t const*) () at /usr/local/lib/libwx_baseu-3.0.so.0
#19 0x0000000800d44d35 in wxApp::OnAssertFailure(wchar_t const*, int, wchar_t const*, wchar_t const*, wchar_t const*) () at /usr/local/lib/libwx_gtk3u_core-3.0.so.0
#20 0x000000080078a201 in  () at /usr/local/lib/libwx_baseu-3.0.so.0
#21 0x0000000800786a13 in wxOnAssert(char const*, int, char const*, char const*, wchar_t const*) () at /usr/local/lib/libwx_baseu-3.0.so.0
#22 0x00000000003fb1b0 in  ()
#23 0x00000000003fa66d in  ()
#24 0x00000000003f9926 in  ()
#25 0x0000000000567450 in  ()
#26 0x00000000005613bb in  ()
#27 0x000000080083f614 in wxEntryStart(int&, wchar_t**) () at /usr/local/lib/libwx_baseu-3.0.so.0
#28 0x000000080083fca0 in wxEntryStart(int&, char**) () at /usr/local/lib/libwx_baseu-3.0.so.0
#29 0x00000000005613ff in  ()
#30 0x000000000037911b in  ()
#31 0x000000080065e000 in  ()
#32 0x0000000000000000 in  ()
Comment 6 Kevin Zheng 2020-03-03 06:30:15 UTC
I compiled with debugging symbols and found that the crash had to do with accessing an empty array while trying to figure out where DATADIR is. This hack works around this issue:

--- src/Dirstructure.cpp.orig   2020-03-03 06:22:16 UTC
+++ src/Dirstructure.cpp
@@ -75,33 +75,7 @@ Dirstructure::Dirstructure()
 wxString Dirstructure::ResourcesDir() const
 {
   // Our ressources dir is somewhere near to the dir the binary can be found.
-  wxFileName exe(wxStandardPaths::Get().GetExecutablePath());
-  
-  // We only need the drive and the directory part of the path to the binary
-  exe.ClearExt();
-  exe.SetName(wxEmptyString);
-  
-  // If the binary is in a source or bin folder the resources dir is one level above
-  wxArrayString dirs = exe.GetDirs();
-  if((dirs.Last().Upper() == wxT("SRC")) || (dirs.Last().Upper() == wxT("BIN")))
-  {
-    exe.RemoveLastDir();
-    dirs = exe.GetDirs();
-  }
-  
-  // If the binary is in the wxMaxima folder the resources dir is two levels above as we
-  // are in MacOS/wxmaxima
-  if((dirs.Last().Upper() == wxT("MACOS")))
-    exe.RemoveLastDir();
-  
-  // If there is a Resources folder the ressources are there
-  if(wxDirExists(exe.GetPath() + wxT("/Resources")))
-    exe.AppendDir("Resources");
-  
-  // If there is a share folder the ressources are there
-  if(wxDirExists(exe.GetPath() + wxT("/share")))
-    exe.AppendDir("share");
-  
+  wxFileName exe("/usr/local/share/wxMaxima");
   return exe.GetPath();
 }

The crash is related to being exe.GetDirs() returning an empty list, so dirs.Last() results in a SIGSEGV. A real "fix" would patch in LOCALBASE.

Unfortunately wxMaxima crashes again for me, this time after the main window starts up, saying:

./src/common/dpycmn.cpp(119): assert "n < GetCount()" failed in wxDisplay(): An invalid index was passed to wxDisplay
Comment 7 Lorenzo Salvadore freebsd_committer 2020-03-03 09:20:31 UTC
(In reply to Kevin Zheng from comment #6)

Thanks Kevin for helping on this.
I wil also try your workaround and see if I can manage to improve on it.

I CC wxgtk30's maintainer as he can maybe be able to help.
Comment 8 Lorenzo Salvadore freebsd_committer 2020-03-03 13:32:45 UTC
If anyone wants to build wxmaxima with debug support, please forget about the option I introduced with the commit in comment #4 and manually define WITH_DEBUG.

Please see, https://svnweb.freebsd.org/ports/head/math/wxmaxima/Makefile?revision=527673&view=markup for more information.
Comment 9 Loïc Bartoletti freebsd_committer 2020-03-09 09:35:41 UTC
Can you try something like this patch:

```
--- src/Dirstructure.cpp.orig   2020-03-09 08:49:58 UTC
+++ src/Dirstructure.cpp
@@ -79,10 +79,11 @@ wxString Dirstructure::ResourcesDir() const

   // We only need the drive and the directory part of the path to the binary
   exe.ClearExt();
-  exe.SetName(wxEmptyString);
+  //exe.SetName(wxEmptyString);
  
   // If the binary is in a source or bin folder the resources dir is one level above
   wxArrayString dirs = exe.GetDirs();
+  if( !dirs.IsEmpty() ) {
   if((dirs.Last().Upper() == wxT("SRC")) || (dirs.Last().Upper() == wxT("BIN")))
   {
     exe.RemoveLastDir();
@@ -93,7 +94,7 @@ wxString Dirstructure::ResourcesDir() const
   // are in MacOS/wxmaxima
   if((dirs.Last().Upper() == wxT("MACOS")))
     exe.RemoveLastDir();
-
+  }
   // If there is a Resources folder the ressources are there
   if(wxDirExists(exe.GetPath() + wxT("/Resources")))
     exe.AppendDir("Resources");
```

With this patch, I haven't segfaults.
Comment 10 Lorenzo Salvadore freebsd_committer 2020-03-10 09:44:34 UTC
Created attachment 212296 [details]
wxmaxima - bugfix

Thanks, lbartoletti for the help! Indeed I tested your patch and it works!
I also upload a diff so that others can apply it while waiting for the commit: as a mentored committer, I cannot apply it immediately and I need to get approval from my mentors before. It will not take long.
Comment 11 Loïc Bartoletti freebsd_committer 2020-03-10 13:09:48 UTC
(In reply to Lorenzo Salvadore from comment #10)

> Thanks, lbartoletti for the help! Indeed I tested your patch and it works!

Good to know! You're welcome.

For me, it's only a workaround (at least for now). I think there is a problem with the function wxStandardPaths::Get().GetExecutablePath() But no time to check  this week
Comment 12 Lorenzo Salvadore freebsd_committer 2020-03-10 14:46:13 UTC
(In reply to Loïc Bartoletti from comment #11)

Do you want me to keep the bug open after the commit so that we can improve the patch later if needed?
Comment 13 Loïc Bartoletti freebsd_committer 2020-03-11 13:29:46 UTC
(In reply to Lorenzo Salvadore from comment #12)
I found the problem, but don't know why it doesn't works on FreeBSD (I'm not a wxwidgets dev, I only need for some ports :/)

`wxStandardPaths::Get().GetExecutablePath()` returns an empty string. You can get the path with `wxGetCwd`

+-  wxFileName exe(wxStandardPaths::Get().GetExecutablePath());
++  wxFileName exe(wxGetCwd());

it's worth to open an issue upstream.
Comment 14 Lorenzo Salvadore freebsd_committer 2020-03-11 14:44:14 UTC
Created attachment 212332 [details]
wxmaxima - bugfix - v2

(In reply to Loïc Bartoletti from comment #13)

Thanks again Loïc! I recreated the patch and I will soon commit it.
Indeed, I also got the empty string from that function: that was where I was stucked when you proposed your first patch :)

When you suggest to report the issue upstream, do you mean to wxmaxima or to wxwidgets? Do you know wxwidgets enough to be able to write a minimal test program and see if that function returns the empty string for it as well? I think that would help understanding who has to fix something (wxmaxima? wxwidgets? FreeBSD?).
Comment 15 Loïc Bartoletti freebsd_committer 2020-03-11 17:17:30 UTC
Created attachment 212337 [details]
testfile for wx paths
Comment 16 Loïc Bartoletti freebsd_committer 2020-03-11 17:17:57 UTC
(In reply to Lorenzo Salvadore from comment #14)

I think it's a problem with wxMaxima for two reasons:
- first the soft crash since it doesn't check an empty array (my if (!dirs.IsEmpty()) )
- I can get paths with a simple program [1]

Finally, for this port, you may patch with `GetInstallPrefix()` which returns "/usr/local" and concatenate with the good dir[2]?

[1] clang++ testwx.cpp `wxgtk3u-3.0-config --cflags --libs` -o testwx
[2] There is an example in my file testwx.cpp at MyFrame::OnInstallPrefix method
Comment 17 Lorenzo Salvadore freebsd_committer 2020-03-11 17:48:23 UTC
(In reply to Loïc Bartoletti from comment #16)

I opened the issue on GitHub: https://github.com/wxMaxima-developers/wxmaxima/issues/1224 .

Thanks for the suggestion about GetInstallPrefix(): I will try that.
Comment 18 commit-hook freebsd_committer 2020-03-13 12:33:48 UTC
A commit references this bug:

Author: salvadore
Date: Fri Mar 13 12:32:49 UTC 2020
New revision: 528347
URL: https://svnweb.freebsd.org/changeset/ports/528347

Log:
  math/wxmaxima: Update to git commit 68fead0

  This is necessary to fix a segmentation fault that affects wxmaxima on
  FreeBSD.

  PR:		244464
  Reported by:	peter.kien@posteo.org
  Approved by:	gerald (mentor)

Changes:
  head/math/wxmaxima/Makefile
  head/math/wxmaxima/distinfo
  head/math/wxmaxima/files/patch-data_CMakeLists.txt
  head/math/wxmaxima/pkg-plist
Comment 19 Lorenzo Salvadore freebsd_committer 2020-03-13 12:35:57 UTC
Fixed, thanks everybody for reporting and helping!