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

Segmentation fault #1442

Closed
ethical-haquer opened this issue Mar 7, 2024 · 15 comments
Closed

Segmentation fault #1442

ethical-haquer opened this issue Mar 7, 2024 · 15 comments

Comments

@ethical-haquer
Copy link
Contributor

I get this output after following the Debian install instructions:

(porcupine-venv) ethical_haquer@liberated-macbook:~$ porcu
log file: /home/ethical_haquer/.cache/porcupine/log/2024-03-06T21-58-20.txt
porcupine.settings WARNING: Can't use /home/ethical_haquer/.cache/porcupine/font_cache.json. Starting Porcupine might take a while.
Segmentation fault
(porcupine-venv) ethical_haquer@liberated-macbook:~$

If you need any more info, just let me know!

@Moosems
Copy link
Contributor

Moosems commented Mar 7, 2024

Would you be able to share the contents of the cache json?

@rdbende
Copy link
Collaborator

rdbende commented Mar 7, 2024

Probably the same as #1370

@rdbende
Copy link
Collaborator

rdbende commented Mar 7, 2024

Could you run these lines in Python repl, and paste the output here? It might already be fixed in a newer version of Tk.

import tkinter

print(tkinter.Tk().tk.call("info", "patchlevel"))

@Akuli
Copy link
Owner

Akuli commented Mar 7, 2024

Also try porcu --verbose.

@ethical-haquer
Copy link
Contributor Author

Thanks for the replies!

Here's the cache json:
font_cache.json

Here's the output of those two lines:
8.6.13

And here's the output of porcu --verbose:

(porcupine-venv) ethical_haquer@liberated-macbook:~$ porcu --verbose
log file: /home/ethical_haquer/.cache/porcupine/log/2024-03-07T11-04-21.txt
porcupine._logs DEBUG: starting Porcupine 2024.02.07 from '/home/ethical_haquer/porcupine-venv/lib/python3.11/site-packages/porcupine'
porcupine._logs DEBUG: PID: 3388
porcupine._logs DEBUG: running on Python 3.11.2 from '/home/ethical_haquer/porcupine-venv/bin/python3'
porcupine._logs DEBUG: sys.platform is 'linux'
porcupine._logs INFO: output from 'uname -a':
Linux liberated-macbook 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux

porcupine._logs INFO: output from 'lsb_release -a':
Distributor ID:	Debian
Description:	Debian GNU/Linux 12 (bookworm)
Release:	12
Codename:	bookworm

porcupine.settings INFO: changed value of 'disabled_plugins': [] --> ['directory_tree']
porcupine.settings INFO: generating change event: <<GlobalSettingChanged:disabled_plugins>>
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.aboutdialog
porcupine.pluginloader DEBUG: imported porcupine.plugins.aboutdialog in 0.392 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.anchors
porcupine.pluginloader DEBUG: imported porcupine.plugins.anchors in 0.500 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.autocomplete
porcupine.pluginloader DEBUG: imported porcupine.plugins.autocomplete in 1.533 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.autoindent
porcupine.pluginloader DEBUG: imported porcupine.plugins.autoindent in 0.646 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.blockcursor
porcupine.pluginloader DEBUG: imported porcupine.plugins.blockcursor in 0.185 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.comment_selected_lines
porcupine.pluginloader DEBUG: imported porcupine.plugins.comment_selected_lines in 0.345 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.desktop_menu
porcupine.pluginloader DEBUG: imported porcupine.plugins.desktop_menu in 0.199 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.drop_to_open
porcupine.pluginloader DEBUG: imported porcupine.plugins.drop_to_open in 0.203 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.editorconfig
porcupine.pluginloader DEBUG: imported porcupine.plugins.editorconfig in 0.664 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.filemanager
porcupine.pluginloader DEBUG: imported porcupine.plugins.filemanager in 19.593 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.filetypes
porcupine.pluginloader DEBUG: imported porcupine.plugins.filetypes in 2.309 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.find
porcupine.pluginloader DEBUG: imported porcupine.plugins.find in 0.349 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.fold
porcupine.pluginloader DEBUG: imported porcupine.plugins.fold in 0.209 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.fullscreen
porcupine.pluginloader DEBUG: imported porcupine.plugins.fullscreen in 0.162 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.geometry
porcupine.pluginloader DEBUG: imported porcupine.plugins.geometry in 0.184 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.git_right_click
porcupine.pluginloader DEBUG: imported porcupine.plugins.git_right_click in 0.209 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.git_status
porcupine.pluginloader DEBUG: imported porcupine.plugins.git_status in 2.784 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.google_search
porcupine.pluginloader DEBUG: imported porcupine.plugins.google_search in 0.173 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.gotoline
porcupine.pluginloader DEBUG: imported porcupine.plugins.gotoline in 0.163 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.hide_project
porcupine.pluginloader DEBUG: imported porcupine.plugins.hide_project in 0.167 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.highlight
porcupine.pluginloader DEBUG: imported porcupine.plugins.highlight in 163.773 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.hover
porcupine.pluginloader DEBUG: imported porcupine.plugins.hover in 0.602 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.indent_block
porcupine.pluginloader DEBUG: imported porcupine.plugins.indent_block in 0.172 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.jump_to_definition
porcupine.pluginloader DEBUG: imported porcupine.plugins.jump_to_definition in 1.162 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.keybindings
porcupine.pluginloader DEBUG: imported porcupine.plugins.keybindings in 0.164 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.langserver
porcupine.pluginloader DEBUG: imported porcupine.plugins.langserver in 106.309 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.linenumbers
porcupine.pluginloader DEBUG: imported porcupine.plugins.linenumbers in 0.026 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.longlinemarker
porcupine.pluginloader DEBUG: imported porcupine.plugins.longlinemarker in 0.231 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.matching_paren
porcupine.pluginloader DEBUG: imported porcupine.plugins.matching_paren in 0.204 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.mergeconflict
porcupine.pluginloader DEBUG: imported porcupine.plugins.mergeconflict in 0.231 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.minimap
porcupine.pluginloader DEBUG: imported porcupine.plugins.minimap in 0.246 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.pastebin
porcupine.pluginloader DEBUG: imported porcupine.plugins.pastebin in 0.448 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.poppingtabs
porcupine.pluginloader DEBUG: imported porcupine.plugins.poppingtabs in 0.500 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.porcupine_debug_prompt
porcupine.pluginloader DEBUG: imported porcupine.plugins.porcupine_debug_prompt in 0.224 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.python_tools
porcupine.pluginloader DEBUG: imported porcupine.plugins.python_tools in 0.195 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.python_venv
porcupine.pluginloader DEBUG: imported porcupine.plugins.python_venv in 0.024 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.reload
porcupine.pluginloader DEBUG: imported porcupine.plugins.reload in 0.160 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.restart
porcupine.pluginloader DEBUG: imported porcupine.plugins.restart in 0.181 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.rightclick_menu
porcupine.pluginloader DEBUG: imported porcupine.plugins.rightclick_menu in 0.023 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.rstrip
porcupine.pluginloader DEBUG: imported porcupine.plugins.rstrip in 0.166 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.run
porcupine.pluginloader DEBUG: imported porcupine.plugins.run in 0.023 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.sort
porcupine.pluginloader DEBUG: imported porcupine.plugins.sort in 0.173 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.statusbar
porcupine.pluginloader DEBUG: imported porcupine.plugins.statusbar in 0.317 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.sun_valley_theme
porcupine.pluginloader DEBUG: imported porcupine.plugins.sun_valley_theme in 0.385 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.tab_closing
porcupine.pluginloader DEBUG: imported porcupine.plugins.tab_closing in 0.187 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.tab_order
porcupine.pluginloader DEBUG: imported porcupine.plugins.tab_order in 0.251 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.tabs2spaces
porcupine.pluginloader DEBUG: imported porcupine.plugins.tabs2spaces in 0.171 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.trailing_newline
porcupine.pluginloader DEBUG: imported porcupine.plugins.trailing_newline in 0.169 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.underlines
porcupine.pluginloader DEBUG: imported porcupine.plugins.underlines in 0.026 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.urls
porcupine.pluginloader DEBUG: imported porcupine.plugins.urls in 0.196 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.welcome
porcupine.pluginloader DEBUG: imported porcupine.plugins.welcome in 0.206 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.windowicon
porcupine.pluginloader DEBUG: imported porcupine.plugins.windowicon in 0.164 milliseconds
porcupine.pluginloader DEBUG: trying to import porcupine.plugins.wrap
porcupine.pluginloader DEBUG: imported porcupine.plugins.wrap in 0.178 milliseconds
porcupine.pluginloader DEBUG: ran filetypes.setup_argument_parser() in 2.794 milliseconds
porcupine._state DEBUG: init() starts
porcupine._state DEBUG: root window created
porcupine._state DEBUG: Tcl/Tk version: 8.6.13
porcupine._state DEBUG: init() done
porcupine.settings DEBUG: initializing continues
porcupine.settings INFO: changed value of 'pygments_style': 'stata-dark' --> 'solarized-dark'
porcupine.settings INFO: generating change event: <<GlobalSettingChanged:pygments_style>>
porcupine.settings INFO: changed value of 'font_family': 'Noto Sans Mono' --> 'Noto Mono'
porcupine.settings INFO: generating change event: <<GlobalSettingChanged:font_family>>
porcupine.settings WARNING: Can't use /home/ethical_haquer/.cache/porcupine/font_cache.json. Starting Porcupine might take a while.
Segmentation fault
(porcupine-venv) ethical_haquer@liberated-macbook:~$

What's strange is that I had previously installed Porcupine, probably v2023.06.27, with no issues on this same computer.

@Akuli
Copy link
Owner

Akuli commented Mar 7, 2024

Porcupine is failing to determine which fonts are monospaced. This is used in the settings dialog. I know this is the problem, because there is a DEBUG level log message when this succeeds, but we aren't getting that in --verbose.

The logic for doing this was changed in #1421, between v2023.06.27 and v2024.02.07.

I am also using Debian 12 on x86_64, so I might be able to reproduce this if I install the same fonts that you have. The problem is, you have a lot of fonts installed :) It would take quite a while for me to find and install them all.

Instead, let's narrow it down by looping through the fonts in a way that keeps going even when the entire Python process crashes. Run this bash script and post the output here:

#!/bin/bash
python3 -c '
import tkinter.font
tkinter.Tk()
print("\n".join(tkinter.font.families()))
' | sort -u | while read font; do
    echo -n "Trying $font... "
    if python3 -c "
import tkinter
from porcupine import settings
settings._dialog_content = tkinter.Tk()
settings._is_monospace('$font')
    "; then
        echo "ok"
    else
        echo "ERROR!!!"
    fi
done

In case I decide to install all fonts you have, please also run:

$ dpkg --get-selections | grep ^fonts

I think this is the third or fourth time the monospace checking code causes this problem. Maybe I should do the entire check in a subprocess, so that I can handle errors better...

@Akuli
Copy link
Owner

Akuli commented Mar 7, 2024

Sorry, I posted a broken version of my bash script above. I edited my message and it now has a working script.

@ethical-haquer
Copy link
Contributor Author

Porcupine is failing to determine which fonts are monospaced. This is used in the settings dialog. I know this is the problem, because there is a DEBUG level log message when this succeeds, but we aren't getting that in --verbose.

The logic for doing this was changed in #1421, between v2023.06.27 and v2024.02.07.

I am also using Debian 12 on x86_64, so I might be able to reproduce this if I install the same fonts that you have. The problem is, you have a lot of fonts installed :) It would take quite a while for me to find and install them all.

Instead, let's narrow it down by looping through the fonts in a way that keeps going even when the entire Python process crashes. Run this bash script and post the output here:

#!/bin/bash
python3 -c '
import tkinter.font
tkinter.Tk()
print("\n".join(tkinter.font.families()))
' | sort -u | while read font; do
    echo -n "Trying $font... "
    if python3 -c "
import tkinter
from porcupine import settings
settings._dialog_content = tkinter.Tk()
settings._is_monospace('$font')
    "; then
        echo "ok"
    else
        echo "ERROR!!!"
    fi
done

Here's the output of the shell script:
script_output.txt

In case I decide to install all fonts you have, please also run:

$ dpkg --get-selections | grep ^fonts

Here's the output of that command:
output.txt

I think this is the third or fourth time the monospace checking code causes this problem. Maybe I should do the entire check in a subprocess, so that I can handle errors better...

What exactly is causing the Segmentation Fault though?

@Akuli
Copy link
Owner

Akuli commented Mar 8, 2024

Here's the output of the shell script:
script_output.txt

Sorry, I forgot to mention that you need to have the venv activated for the script to work. Can you run it again after a source ~/porcupine-venv/bin/activate?

Here's the output of that command:
output.txt

Looks good! I will try to reproduce the problem later today.

What exactly is causing the Segmentation Fault though?

A bug in Tk.

@Akuli
Copy link
Owner

Akuli commented Mar 8, 2024

I can't reproduce this even after installing the same font packages that you have. But I will be able to fix this once I know which fonts cause crashing (that's what my bash script is supposed to check).

@ethical-haquer
Copy link
Contributor Author

ethical-haquer commented Mar 8, 2024

Here's the output of the shell script:
script_output.txt

Sorry, I forgot to mention that you need to have the venv activated for the script to work. Can you run it again after a source ~/porcupine-venv/bin/activate?

Absolutely! Here's the new output:

ethical_haquer@liberated-macbook:~$ source ~/porcupine-venv/bin/activate
(porcupine-venv) ethical_haquer@liberated-macbook:~$ ./script.sh
Trying aakar... ok
Trying Abyssinica SIL... ok
Trying Aharoni CLM... ok
Trying Amiri... ok
Trying Amiri Quran... ok
Trying Amiri Quran Colored...

It stops on Amiri Quran Colored.

Here's the output of that command:
output.txt

Looks good! I will try to reproduce the problem later today.

What exactly is causing the Segmentation Fault though?

A bug in Tk.

👍

@Akuli
Copy link
Owner

Akuli commented Mar 8, 2024

I don't know why the bash script is stopping, so I rewrote it in python. Try running this Python script (with python3 filename.py after activating the venv):

import sys
import tkinter.font
import subprocess

tkinter.Tk().withdraw()

for font in sorted(set(tkinter.font.families())):
    print(f"Trying {font}...", end=" ", flush=True)

    ret = subprocess.call([sys.executable, '-c', f'''
import tkinter
from porcupine import settings
settings._dialog_content = tkinter.Tk()
settings._is_monospace({font!r})
'''])

    if ret == 0:
        print("ok")
    else:
        print("ERROR!!!")

@ethical-haquer
Copy link
Contributor Author

I don't know why the bash script is stopping, so I rewrote it in python. Try running this Python script (with python3 filename.py after activating the venv):

import sys
import tkinter.font
import subprocess

tkinter.Tk().withdraw()

for font in sorted(set(tkinter.font.families())):
    print(f"Trying {font}...", end=" ", flush=True)

    ret = subprocess.call([sys.executable, '-c', f'''
import tkinter
from porcupine import settings
settings._dialog_content = tkinter.Tk()
settings._is_monospace({font!r})
'''])

    if ret == 0:
        print("ok")
    else:
        print("ERROR!!!")

Here's the output:
script_output.txt

"Amiri Quran Colored" is the only one it errors on.

@Akuli Akuli closed this as completed in 59fe663 Mar 8, 2024
@Akuli Akuli reopened this Mar 8, 2024
@Akuli
Copy link
Owner

Akuli commented Mar 8, 2024

I released a fix. Try installing today's release and let me know if it works. You can delete the porcupine-venv folder if you want a fresh start.

@ethical-haquer
Copy link
Contributor Author

I released a fix. Try installing today's release and let me know if it works. You can delete the porcupine-venv folder if you want a fresh start.

Sorry for the late reply!
It indeed works, thanks for fixing this one-off bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants