# HG changeset patch # User Edouard Tisserant # Date 1630810894 -7200 # Node ID 3d736248ab3b10d78cf83528c7aa0e2ebb9279b2 # Parent 0ffb416255925a3e6ee230995ec6afcc6a4f92d1 Fix exception when canvas becomes null because of window resize, and avoid useless parameter+condition in GetLogicalDC diff -r 0ffb41625592 -r 3d736248ab3b editors/Viewer.py --- a/editors/Viewer.py Thu Sep 02 22:18:14 2021 +0200 +++ b/editors/Viewer.py Sun Sep 05 05:01:34 2021 +0200 @@ -825,15 +825,14 @@ def GetViewScale(self): return self.ViewScale - def GetLogicalDC(self, buffered=False): - if buffered: - bitmap = wx.Bitmap(*self.Editor.GetClientSize()) - dc = wx.MemoryDC(bitmap) - else: - dc = wx.ClientDC(self.Editor) + def PrepareDC(self, dc): dc.SetFont(self.GetFont()) self.Editor.DoPrepareDC(dc) dc.SetUserScale(self.ViewScale[0], self.ViewScale[1]) + + def GetLogicalDC(self): + dc = wx.ClientDC(self.Editor) + self.PrepareDC(dc) return dc def RefreshRect(self, rect, eraseBackground=True): @@ -3681,9 +3680,13 @@ self.rubberBand.Draw(dc) def OnPaint(self, event): - dc = self.GetLogicalDC(True) + event.Skip() + sx,sy = self.Editor.GetClientSize() + if sx <= 0 or sy <= 0 : + return + dc = wx.MemoryDC(wx.Bitmap(sx,sy)) + self.PrepareDC(dc) self.DoDrawing(dc) wx.BufferedPaintDC(self.Editor, dc.GetAsBitmap()) if self.Debug: DebugViewer.RefreshNewData(self) - event.Skip()