GimelStudio / Gimel-Studio

Old repo of the node-based image editor. See https://github.com/GimelStudio/GimelStudio for the next generation of Gimel Studio :rocket:
https://gimelstudio.github.io
Apache License 2.0
59 stars 8 forks source link

Text node - font error #18

Closed Correct-Syntax closed 3 years ago

Correct-Syntax commented 4 years ago

Unfortunately, I have been getting OSError: invalid face handle after merging your pull request, @iwoithe . This looks like it could be a bug with Pillow (issue).

I may disable the text node for now until this is resolved.

iwoithe commented 4 years ago

Hi @Correct-Syntax, This issue is a little awkward as I have never got this error, so I would like the traceback and the steps to reproduce the error (if there are any).

So far, the only error I can reproduce consistently is when I type quickly into the StringProp - and even then it can take a lot of tries before Gimel Studio crashes. Unfortunately, when this happens, it has a message of Process finished with code -1073740791 (0xC0000409) which is not exactly helpful. Not sure how to solve it.

Correct-Syntax commented 4 years ago

@iwoithe,

the traceback and the steps to reproduce the error

On Windows:

  1. Add Text node
  2. Connect Text node to Output node
  3. Connect Image node to Text node

    Results in error:

    Traceback (most recent call last):
    File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
    File "C:\Users\doall\GimelStudio\src\GimelStudio\renderer\thread.py", line 53, in run
    render_image = self._parent._renderer.Render(self._parent._nodeGraph.GetNodes())
    File "C:\Users\doall\GimelStudio\src\GimelStudio\renderer\renderer.py", line 70, in Render
    rendered_image = self.RenderNodeGraph(output_node, nodes)
    File "C:\Users\doall\GimelStudio\src\GimelStudio\renderer\renderer.py", line 96, in RenderNodeGraph
    return output_data.RenderImage()
    File "C:\Users\doall\GimelStudio\src\GimelStudio\renderer\output_node.py", line 48, in RenderImage
    image = eval_info.node.EvaluateNode(eval_info)
    File "C:\Users\doall\GimelStudio\src\GimelStudio\corenodes\draw\text_node.py", line 118, in NodeEvaluation
    draw.text(text_pos, text, font=fnt, fill=font_color)
    File "C:\Python38\lib\site-packages\PIL\ImageDraw.py", line 353, in text
    draw_text(ink)
    File "C:\Python38\lib\site-packages\PIL\ImageDraw.py", line 310, in draw_text
    mask, offset = font.getmask2(
    File "C:\Python38\lib\site-packages\PIL\ImageFont.py", line 471, in getmask2
    size, offset = self.font.getsize(
    OSError: invalid face handle
Correct-Syntax commented 4 years ago

@iwoithe,

Unfortunately, the above steps don't always produce the error. (Frustrating!!)

This may have something to do with the renderer threading issues which still need to be resolved. We can revert to the old "method" which was used in v0.4.2. It rarely crashes unlike my "new/current" implementation!

So far, the only error I can reproduce consistently is when I type quickly into the StringProp - and even then it can take a lot of tries before Gimel Studio crashes. Unfortunately, when this happens, it has a message of Process finished with code -1073740791 (0xC0000409) which is not exactly helpful. Not sure how to solve it.

I have had similar error messages and crashes. This is (again) definitely due to the renderer threading issues. I really need to work on it and get it fixed.

As far as the crashes when typing quickly, I am thinking that what needs to implemented is a text "bounce" feature. Meaning that when the user types a char into the stringprop input and the wx event is fired, maybe delay the event from happening (thus delaying the render) until the user has paused or finished typing.

Let me know what your thoughts about the threading issues here: #19.

iwoithe commented 4 years ago

Hi @Correct-Syntax, Okay. Now I'm more than confused. I recently got an opportunity to try the text node on Windows, and it worked (see screenshot below).

original

After trying the steps to reproduce, I still could not get the error. The only difference that I can see is that your using Python 3.8 while I have been using Python 3.7. But I don't think that would be the reason for the error.

Metallicow commented 4 years ago

Not sure, but it might be Python3.8 related. On the wxPython side changes in a string mismatch with locale caused weird error with images. Might be similar but affecting the Pillow lib. First thing to do is to figure out exactly how you can reproduce the error with 3.8, then try to reproduce it with 3.7. Make sure you are running the same lib versions for both pythons. Then if you absolutely cannot reproduce the error on 3.7, then Python 3.8 would be the suspect. And if so, it might take ya a while to figure out what is causing it. Edit: the string mismatch in locale affected MSW windows btw.

Correct-Syntax commented 4 years ago

I seem to still be getting

Segmentation fault (core dumped)

or

[xcb] Unknown sequence number while processing reply
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
python3: ../../src/xcb_io.c:641: _XReply: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)

On Linux Mint, the fonts don't seem to be loading either.

Screenshot from 2020-11-08 14-10-39_LI

iwoithe commented 4 years ago

Interesting. My first thought after looking at the screenshot was that there is a typo in the fonts file location (/usr/share/fonts/TTF/) but it looks correct (on Xfce 4.12 Slackware). Clarification that this is the correct file path for (TTF) fonts would be appreciated.

I seem to still be getting

Segmentation fault (core dumped)

I don't know how to fix it at this point, but take a look at this stackoverflow question.

Metallicow commented 4 years ago

No. Providing a fonts location won't make an error, unless os.path.exists(path) didn't return True for some reason. What is your problem exactly...? Is it exactly with fonts. How are you trying to load a font...? If all else, go into the code and start commenting out each line and work your way upwards. print('DEBUG statement') help

Correct-Syntax commented 4 years ago

Even without threading, the node crashes the program.

I did some tests and it seems that the actual draw method crashes the program. Leaving out the font param (to the default Pillow font) works fine, though.

Correct-Syntax commented 3 years ago

Hopefully moving the node backend to something like OpenImageIO will help. I need to look into it though.