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

Had this issue since installed a certain update in windows 11, is this a windows issue or is it a comtypes issue? OSError: exception: access violation writing #476

Open
ninjatall12 opened this issue Mar 25, 2023 · 10 comments
Labels
question Further information is requested

Comments

@ninjatall12
Copy link

Comtypes.txt

@junkmd
Copy link
Collaborator

junkmd commented Mar 26, 2023

I think that your report is similar to the following issue.
#89, #98, #193

Can you tell me what COM library you were trying to use and how it worked in environments other than Windows 11?

And, error messages and code snippets should be listed as highlighting-code-blocks as shown below.

https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks

@junkmd junkmd added the question Further information is requested label Mar 26, 2023
@ninjatall12
Copy link
Author

It is not my program but a third party library that i am using called DXcam which is a screenshot library that wraps around Desktop Duplication Api to take screenshots.

The provider of the third party library i believe is no longer maintaining the library and i want to learn how to fix some issues.

https://github.com/ra1nty/DXcam/search?q=comtypes

All i know it happens when i alt tab out of a game using vulkan or directx11 have not tested other games.

I know it is not your job to go read and diagnose someone elses code and i apologise in advance.

@junkmd
Copy link
Collaborator

junkmd commented Mar 27, 2023

It doesn't matter that it is not your code.

What I would like to know is at what point did the error occur when you tried to "take screenshots" using DXcam.

I want "code snippet that reproduces the issue".

For example, if you "got an IndexError with a list", I want the code similar to below.

>>> foo = []
>>> foo[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

@ninjatall12
Copy link
Author

ninjatall12 commented Mar 27, 2023

 except comtypes.COMError as ce:
            if ctypes.c_int32(DXGI_ERROR_ACCESS_LOST).value == ce.args[0]:
                return False
            if ctypes.c_int32(DXGI_ERROR_WAIT_TIMEOUT).value == ce.args[0]:
                self.updated = False
                return True
            else:
                raise ce
        try:
            self.texture = res.QueryInterface(ID3D11Texture2D)
        except comtypes.COMError as ce:
            self.duplicator.ReleaseFrame()
        self.updated = True
        return True

I am 100% sure that the error lies between these codes. as the error only occurs when switching tabs

@junkmd
Copy link
Collaborator

junkmd commented Mar 28, 2023

OK, I see where the error might be occurring.
Are you sure it is the code block in the permalink below?
https://github.com/ra1nty/DXcam/blob/e578c0d8bfcabf50a65c4dac764e0d8b318494b1/dxcam/core/duplicator.py#L21-L43

How were you calling the function or class when this error occurred?
We need it so that community members, including myself, can try to reproduce the error.

@ninjatall12
Copy link
Author

ninjatall12 commented Mar 28, 2023

The function was called by the _grab function but here is also the grab function incase any context is needed. These are located in the dxcam.py file

def grab(self, region: Tuple[int, int, int, int] = None):
        if region is None:
            region = self.region
        self._validate_region(region)
        frame = self._grab(region)
        return frame

    def _grab(self, region: Tuple[int, int, int, int]):
        if self._duplicator.update_frame():
            if not self._duplicator.updated:
                return None
            self._device.im_context.CopyResource(
                self._stagesurf.texture, self._duplicator.texture
            )
            self._duplicator.release_frame()
            rect = self._stagesurf.map()
            frame = self._processor.process(
                rect, self.width, self.height, region, self.rotation_angle
            )
            self._stagesurf.unmap()
            return frame
        else:
            self._on_output_change()
            return None        

@junkmd
Copy link
Collaborator

junkmd commented Mar 28, 2023

What I am asking is how you are using DXcam.

For example, if you are "using a list and an IndexError was raised", I don't want the source code that implements the list of Python, I want code that can reproduce the situation in which the error actually occurred, such as the following.

>>> spam = ["foo", "bar", "baz"]
>>> spam[4]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

@vasily-v-ryabov
Copy link
Collaborator

First thanks for letting me know about such library DXCam and Duplication API. It might be useful to pywinauto project where we use Pillow to take screenshots (not sure it would work in DirectX games).

Regarding the issue, it seems error reporting could be improved in DXCam project. OSError usually means some error code returned by a system call, and error text description can be obtained by another system call (GetLastError or something like that). I can't promise I will have time for this issue soon. But it's interesting.

@vasily-v-ryabov
Copy link
Collaborator

Well, sorry I read the text log attached to the first post in this thread, and there is already such information handled by comtypes. It looks like we need to dive into DXCam code anyway. It could be some aligning issue (could be in comtypes too) or wrong sequence of Duplication API calls or missing error handling if some errors are expected.

@junkmd
Copy link
Collaborator

junkmd commented Apr 19, 2024

Is there an update on this issue?

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

No branches or pull requests

3 participants