Suzie1 / ComfyUI_Comfyroll_CustomNodes

Custom nodes for SDXL and SD1.5 including Multi-ControlNet, LoRA, Aspect Ratio, Process Switches, and many more nodes.
https://civitai.com/models/183551/comfyui-comfyroll-custom-nodes
525 stars 68 forks source link

An error occurred while retrieving information for the 'CR Select Font' node on Linux (Ubuntu 22.04) #101

Closed kidyudiqy closed 6 months ago

kidyudiqy commented 6 months ago

Running on Ubuntu 22.04. After I updated Comfyroll to the newest version (Comfyroll Studio v1.66) this error pops up:

[ERROR] An error occurred while retrieving information for the 'CR Select Font' node.
Traceback (most recent call last):
  File "/comfy/server.py", line 420, in get_object_info
    out[x] = node_info(x)
             ^^^^^^^^^^^^
  File "/comfy/server.py", line 398, in node_info
    info['input'] = obj_class.INPUT_TYPES()
                    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/comfy/custom_nodes/ComfyUI_Comfyroll_CustomNodes/nodes/nodes_graphics_text.py", line 458, in INPUT_TYPES
    font_dir = os.path.join(system_root, 'Fonts')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 76, in join
TypeError: expected str, bytes or os.PathLike object, not NoneType

https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/blob/3a9779f82cc2498cd8c1395c59b6a5832f672229/nodes/nodes_graphics_text.py#L457-L459 I think it's because linux doesn't have SystemRoot in its env vars.

System-wide fonts on linux is usually found at /usr/share/fonts, but often fonts are installed locally for a user on their $HOME folder instead, so you might want to also check ~/.fonts and ~/.local/share/fonts too.

(Tangentially related: You can also install fonts on per-user basis on Windows, so you also need to check C:\Users\{username}\AppData\Local\Microsoft\Windows\Fonts too, I think.)

Grant-CP commented 6 months ago

Seconding that I'm getting the exact same issue (updated all nodes and python libraries today) on my Ubuntu VM.

slbillups commented 6 months ago

@Suzie1 or any other contributor that sees this, I assume the naming convention was correct before the two new nodes were added but didn't really dig deep - this resolved the issue for me on Linux Mint(which should also work for Ubuntu/most other Debian flavors).


class CR_SelectFont:
    @classmethod
    def INPUT_TYPES(cls):
        if platform.system() == "Windows":
            system_root = os.environ.get("SystemRoot")
            font_dir = os.path.join(system_root, "Fonts") if system_root else None
        # The class was throwing a TypeError during page load/refresh.
        # Added default debian-based Linux & MacOS font dirs
        elif platform.system() == "Linux":
            font_dir = "/usr/share/fonts/truetype"
        elif platform.system() == "Darwin":
            font_dir = "/System/Library/Fonts"

        return {
            "required": {
                "font_name": (font_dir,),
            }
        }

    RETURN_TYPES = ("STRING", "STRING")
    RETURN_NAMES = ("font_name", "show_help")
    FUNCTION = "select_font"
    CATEGORY = icons.get("Comfyroll/Graphics/Text")

    def select_font(self, font_name):
        show_help = "https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki/Text-Nodes#cr-select-font"
        return (
            font_name,
            show_help,
        )
Suzie1 commented 6 months ago

many thanks for reporting this

@slbillups I made this change. please can you test and let me know if its okay

@kidyudiqy Thanks for mentioning the local fonts. I may need to add this.

fixed in version: 1.71.1

Suzie