cmbruns / pyopenxr

Unofficial python bindings for OpenXR access to VR and AR devices
Apache License 2.0
103 stars 8 forks source link

Can not print any OpenXR objects #61

Closed el-dee closed 12 months ago

el-dee commented 2 years ago

When trying to print any object created by pyopenxr, the program crashes with an exception similar to this :

  File "/home/ld/Projects/pyopenxr/src/xr/typedefs.py", line 890, in __str__
    return f"xr.SwapchainImageAcquireInfo(next_structure={self.next_structure}, structure_type={self.structure_type})"
AttributeError: 'SwapchainImageAcquireInfo' object has no attribute 'next_structure'

The root cause is that the name of the next and type fields are changed into respectively next_structure and structure_type but the fields themselves keep their original name and so the code :

    def __str__(self) -> str:
        return f"xr.xxxxxxxx(next_structure={self.next_structure}, structure_type={self.structure_type})"

fails.

cmbruns commented 2 years ago

I can reproduce this problem. Sample repro script:

import xr
apl = xr.ApiLayerProperties()
print(apl)

Expected Behavior: It should print something and not raise an exception. Actual behavior, AttributeError is raised like in the synopsis.

self = <[AttributeError("'ApiLayerProperties' object has no attribute 'next_structure'") raised in repr()] ApiLayerProperties object at 0x1bc680f5840>

def __str__(self) -> str:
  return f"xr.ApiLayerProperties(layer_name={self.layer_name}, spec_version={self.spec_version}, layer_version={self.layer_version}, description={self.description}, next_structure={self.next_structure}, structure_type={self.structure_type})"

E AttributeError: 'ApiLayerProperties' object has no attribute 'next_structure'

cmbruns commented 2 years ago

We renamed those attributes because next and type are python built-in functions. This problem is likely fixed in commit d021703b9b368171ef24be78955eca68779f8283

el-dee commented 2 years ago

There are still a couple of next_structure and structure_type in src/xr/platform/linux.py. Updating the file is trivial, but I'm not 100% sure where to do the modification in the generator.

cmbruns commented 2 years ago

@el-deel thank you. Hmm it seems src/xr/platform/linux.py did not get updated in the March updates. I'll try to repair this over the weekend.