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

[Support] Windows Error 0xc0000002 Exception #644

Closed
moi15moi opened this issue Oct 22, 2024 · 3 comments
Closed

[Support] Windows Error 0xc0000002 Exception #644

moi15moi opened this issue Oct 22, 2024 · 3 comments
Labels
shared_info use cases, tips and troubleshoots

Comments

@moi15moi
Copy link
Contributor

I am pretty sure it is a skill issue and comtypes may have nothing to do with my problem, but I can't find why I always get the exception.

Traceback (most recent call last):
  File "C:\Users\moi15moi\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\_post_coinit\unknwn.py", line 426, in __del__
    self.Release()
  File "C:\Users\moi15moi\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\_post_coinit\unknwn.py", line 560, in Release
    return self.__com_Release()  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^
OSError: [WinError -1073741822] Windows Error 0xc0000002

From what I can see in the Microsoft documentation, 0xc0000002 is STATUS_NOT_IMPLEMENTED. I don't really understand why it happens.

It occurs when I run this code with this PR (due to the high dependency across various parts of the code, creating a small, self-contained example is quite difficult):

from find_system_fonts_filename import get_font_fallback
get_font_fallback("Arial", 700, False, "😁")

If I add a print(self) here, it prints me <POINTER(IDWriteFont) ptr=0x2949ed64a50 at 2949e84c5d0>.
I'm wondering if it happens because here, I pass a pointer of my IDWriteFont that I use here.

Do you have any idea what I could do wrong?

My environment

Python version: 3.11.7
comtypes version: 1.4.8

@junkmd
Copy link
Collaborator

junkmd commented Oct 22, 2024

I believe this issue is due to the behavior of IDWriteFont. Since I am not very familiar with this interface, I can't provide quick and accurate advice, but I would like to assist in resolving the issue.

If we can solve this problem, it could serve as a useful reference for troubleshooting when manually defining custom interfaces using comtypes in the future.

I noticed that the program flow does not proceed after the HasCharacter call. What happens if you don't call HasCharacter or call a different method instead?

I'm not entirely sure why the error occurs when Release is called. It’s unclear whether the issue stems from incorrect parameter specifications for the COM methods as seen in #521 and #607, or if it's caused by something entirely different.

@moi15moi
Copy link
Contributor Author

moi15moi commented Oct 22, 2024

What happens if you don't call HasCharacter or call a different method instead?

It doesn't seems that HasCharacter is the problem because I added some print and a call of GetInformationalStrings in this commit and now the output is:

2b780b<POINTER(IDWriteFont) ptr=0x1d594494840 at 1d594344950>
This print is displayed
Before HasCharacter
After HasCharacter
Exception ignored in: <function _compointer_base.__del__ at 0x000001D592A854E0>
Traceback (most recent call last):
  File "C:\Users\moi15moi\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\_post_coinit\unknwn.py", line 386, in __del__   
    self.Release()
  File "C:\Users\moi15moi\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\_post_coinit\unknwn.py", line 534, in Release   
    return self.__com_Release()  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^
OSError: [WinError -1073741822] Windows Error 0xc0000002

Edit:
Note that if I try to call font.AddRef(), before the for loop, I get this error

Traceback (most recent call last):
  File "C:\Users\moi15moi\Documents\GitHub\FindSystemFontsFilename\find_system_fonts_filename\windows\windows_fonts.py", line 344, in get_font_fallback
    font.AddRef()
  File "C:\Users\moi15moi\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\_post_coinit\unknwn.py", line 530, in AddRef    
    return self.__com_AddRef()  # type: ignore
           ^^^^^^^^^^^^^^^^^^^
OSError: [WinError -1073741822] Windows Error 0xc0000002

@moi15moi
Copy link
Contributor Author

I fixed the bug in this commit. I am surprised that I could call font.HasCharacter even when the font wasn’t properly instantiated with font_collection.GetFontFromFontFace(fontFace, font_ptr[0]). The issue arose from not creating the font object correctly.

Now, I ensure the font is properly initialized by calling font_collection.GetFontFromFontFace(fontFace, font_ptr). This guarantees that the font is correctly instantiated before invoking HasCharacter. Now, the code behaves as expected.

@junkmd junkmd added the shared_info use cases, tips and troubleshoots label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shared_info use cases, tips and troubleshoots
Projects
None yet
Development

No branches or pull requests

2 participants