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

Random crashes using Latent2RGB preview method #5012

Closed
LukeG89 opened this issue Sep 21, 2024 · 10 comments
Closed

Random crashes using Latent2RGB preview method #5012

LukeG89 opened this issue Sep 21, 2024 · 10 comments
Labels
Potential Bug User is reporting a bug. This should be tested.

Comments

@LukeG89
Copy link

LukeG89 commented Sep 21, 2024

Expected Behavior

Generating without crashes using Latent2RGB preview.

Actual Behavior

After some generations, ComfyUI crashes when is about to preview the latest image in the Preview Image node.
It can happen after only 5-6 images or up to 20 or more, pretty random behavior.
The crash also makes reboot my external SSD drive, where my ComfyUI portable is installed.

After some testing, I tried switching to TAESD method and the issue was gone, so I guess Latent2RGB is the problem.

Steps to Reproduce

Select Latent2RGB as preview method and start generating.

Debug Logs

Exception in thread Thread-9 (prompt_worker):
Traceback (most recent call last):
  File "E:\python_embeded\Lib\site-packages\PIL\ImageFile.py", line 547, in _save
AttributeError: '_idat' object has no attribute 'fileno'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\ComfyUI\execution.py", line 323, in execute
  File "E:\ComfyUI\execution.py", line 198, in get_output_data
  File "E:\ComfyUI\execution.py", line 169, in _map_node_over_list
  File "E:\ComfyUI\execution.py", line 158, in process_inputs
  File "E:\ComfyUI\nodes.py", line 1511, in save_images
  File "E:\python_embeded\Lib\site-packages\PIL\Image.py", line 2568, in save
  File "E:\python_embeded\Lib\site-packages\PIL\PngImagePlugin.py", line 1431, in _save
  File "E:\python_embeded\Lib\site-packages\PIL\ImageFile.py", line 551, in _save
  File "E:\python_embeded\Lib\site-packages\PIL\ImageFile.py", line 571, in _encode_tile
  File "E:\python_embeded\Lib\site-packages\PIL\PngImagePlugin.py", line 1101, in write
  File "E:\python_embeded\Lib\site-packages\PIL\PngImagePlugin.py", line 1088, in putchunk
OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "threading.py", line 1045, in _bootstrap_inner
  File "threading.py", line 982, in run
  File "E:\ComfyUI\main.py", line 125, in prompt_worker
    e.execute(item[2], prompt_id, item[3], item[4])
  File "E:\ComfyUI\custom_nodes\rgthree-comfy\__init__.py", line 217, in rgthree_execute
  File "E:\ComfyUI\execution.py", line 500, in execute
  File "E:\ComfyUI\execution.py", line 390, in execute
  File "E:\ComfyUI\execution.py", line 390, in <listcomp>
  File "E:\ComfyUI\execution.py", line 242, in format_value
  File "E:\python_embeded\Lib\site-packages\torch\_tensor.py", line 523, in __repr__
  File "E:\python_embeded\Lib\site-packages\torch\_tensor_str.py", line 706, in _str
  File "contextlib.py", line 137, in __enter__
  File "E:\python_embeded\Lib\site-packages\torch\utils\_python_dispatch.py", line 235, in _disable_current_modes
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 936, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1073, in get_code
  File "<frozen importlib._bootstrap_external>", line 1131, in get_data
OSError: [Errno 22] Invalid argument

Other

No response

@LukeG89 LukeG89 added the Potential Bug User is reporting a bug. This should be tested. label Sep 21, 2024
@ltdrdata
Copy link
Collaborator

For devevloper:
One of the cases that causes this error is when the image size is incorrect, such as (0, 100).
This is an aspect worth checking when investigating.
python-pillow/Pillow#3208

@ltdrdata
Copy link
Collaborator

The current log is incomplete.
Please disable rgthree, retry to reproduce the situation, and upload the complete log.

@LukeG89
Copy link
Author

LukeG89 commented Sep 22, 2024

Tested all this morning, tried with both rgthree enabled and disabled, gradually removed rgthree nodes and bookmarks, but the problem still persist.

I didn't get any issue generating with the default workflow, so maybe there is another custom node in my workflow that conflicts.

Here's the workflow I use:
custom_workflow.json

In my tests I start queueing 30 batches.

Here's the latest debug logs (with rgthree disabled):
debug_logs.txt

@ltdrdata
Copy link
Collaborator

What is your pillow version?
If pillow is not version 10.4.0, try upgrading it.

And the issue is still persist.

ComfyUI/nodes.py

Line 1515 in 6ad0ddb

img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)

Please modify line 1515 of ComfyUI/nodes.py as follows and record the log again.

            ### edit like this -->
            try:
                img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)
            except Exception as e:
                print(f"[DEBUG] img: {img.size}")
                print(f"[DEBUG] path: {os.path.join(full_output_folder, file)}")
                print(f"[DEBUG] metadata: {metadata}")
                print(f"[DEBUG] compress_level: {self.compress_level}")
            ### <--

@LukeG89
Copy link
Author

LukeG89 commented Sep 22, 2024

What is your pillow version?
If pillow is not version 10.4.0, try upgrading it.

Yes, Pillow is 10.4.0.

Please modify line 1515 of ComfyUI/nodes.py as follows and record the log again.

I don't know if I did it right because I edited nodes.py using notepad.
Here's the new debug logs:
Debug_logs_nodes-py_mod.txt

@ltdrdata
Copy link
Collaborator

How about this?

            ### edit like this -->
            try:
                img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)
            except Exception as e:
                print(f"[DEBUG] RETRY")
                img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)
                print(f"[DEBUG] RETRY - SUCCESS")
            ### <--

@LukeG89
Copy link
Author

LukeG89 commented Sep 22, 2024

How about this?

        ### edit like this -->
        try:
            img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)
        except Exception as e:
            print(f"[DEBUG] RETRY")
            img.save(os.path.join(full_output_folder, file), pnginfo=metadata, compress_level=self.compress_level)
            print(f"[DEBUG] RETRY - SUCCESS")
        ### <--

Here's the result:
Debug_logs_nodes-py_mod-2.txt

@LukeG89
Copy link
Author

LukeG89 commented Sep 22, 2024

I think I copied the code wrong in the previous test, I fixed it and tested it again.
However, the error is still the same:
Debug_logs_nodes-py_mod-2-2.txt

@LukeG89
Copy link
Author

LukeG89 commented Sep 23, 2024

@ltdrdata I found the cause! It's the Manager!

  • First, I simplified my workflow to only have ComfyUI nodes inside: Still crashing. 😞
  • Then, I disabled one by one my custom nodes, remaining only with the Manager: Still crashing. 😞
  • And finally, I disabled the Manager and used --preview-method latent2rgb argument: No crashing! 🎉

Here's the debug logs with only the Manager enabled:
Debug_logs_only_manager_enabled.txt

And this is the simplified workflow that I used:
custom_workflow_simplified.json

@LukeG89
Copy link
Author

LukeG89 commented Sep 26, 2024

I think my crashing problem has been resolved somehow, so I am closing the issue for now.

Thanks @ltdrdata for your assistance! ❤️

@LukeG89 LukeG89 closed this as completed Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Potential Bug User is reporting a bug. This should be tested.
Projects
None yet
Development

No branches or pull requests

2 participants