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

Provide extra tip for fixing monitor-swap error #385

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions wgpu/backends/rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def print_storage_report(topic, d):
class GPUCanvasContext(base.GPUCanvasContext):
def __init__(self, canvas):
super().__init__(canvas)
self._surface_size = (-1, -1)
self._surface_size = (-1, -1, -1)
self._surface_id = None
self._internal = None
self._current_texture = None
Expand All @@ -443,8 +443,15 @@ def get_current_texture(self):
)
if self._current_texture is None:
self._create_native_swap_chain_if_needed()
# H: WGPUTextureView f(WGPUSwapChain swapChain)
view_id = libf.wgpuSwapChainGetCurrentTextureView(self._internal)
try:
# H: WGPUTextureView f(WGPUSwapChain swapChain)
view_id = libf.wgpuSwapChainGetCurrentTextureView(self._internal)
except Exception as err:
extra_msg = "\nThis may be caused by dragging the window to a monitor with different dpi. "
extra_msg += "Resize window to proceed.\n"
err.args = (err.args[0] + extra_msg,) + err.args[1:]
raise err from None

size = self._surface_size[0], self._surface_size[1], 1
self._current_texture = GPUTextureView(
"swap_chain", view_id, self._device, None, size
Expand All @@ -465,9 +472,11 @@ def present(self):
def _create_native_swap_chain_if_needed(self):
canvas = self._get_canvas()
psize = canvas.get_physical_size()
if psize == self._surface_size:
ref_size = psize[0], psize[1], canvas.get_pixel_ratio()

if ref_size == self._surface_size:
return
self._surface_size = psize
self._surface_size = ref_size

if self._surface_id is None:
self._surface_id = get_surface_id_from_canvas(canvas)
Expand Down
Loading