cmbruns/pyopenxr

Can not print any OpenXR objects

Closed this issue · 4 comments

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.

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'

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

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.

@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.