GLWindow.OnPaint() broken on Windows
|Reported by:||glynn||Owned by:|
GLWindow.OnPaint() (in nviz_mapdisp.py) calls:
dc = wx.PaintDC(self)
On Windows, wx.PaintDC() can only be called in an EVT_PAINT handler, but GLWindow.OnPaint() is called from at least two other places: GLWindow.OnMouseAction() (nviz_mapdisp.py:226) and MapFrame.AddToolbar() (mapdisp.py:417). The latter causes an exception when switching to "3D View":
Traceback (most recent call last): File "C:\msys\1.0\home\glynn\src\grass-7.0\dist.i686-pc-mingw32\etc\gui\wxpython\gui_modules\toolbars.py", line 322, in OnSelectTool self.parent.AddToolbar("nviz") File "C:\msys\1.0\home\glynn\src\grass-7.0\dist.i686-pc-mingw32\etc\gui\wxpython\gui_modules\mapdisp.py", line 417, in AddToolbar self.MapWindow3D.OnPaint(None) # -> LoadData File "C:\msys\1.0\home\glynn\src\grass-7.0\dist.i686-pc-mingw32\etc\gui\wxpython\gui_modules\nviz_mapdisp.py", line 163, in OnPaint dc = wx.PaintDC(self) File "C:\Program Files\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py", line 4804, in __init__ _gdi_.PaintDC_swiginit(self,_gdi_.new_PaintDC(*args, **kwargs)) wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at ..\..\src\msw\dcclient.cpp(219) in wxPaintDC::wxPaintDC(): wxPaintDC may be created only in EVT_PAINT handler!
I note that the created DC isn't actually used, so I'm assuming this it's being created to keep Windows happy (if you don't create a PaintDC, Windows won't "validate" the rectangle and will just keep send PAINT messages).
I'm also assuming that OnPaint() is being called to ensure that the state gets fully initialised. If you just want to force a redraw, you would normally do so asynchronously using wx.Window.Refresh(). But that won't work if you're counting on OnPaint() having been called before proceeding.
I think that OnPaint() should probably be split into e.g. OnPaint() and DoPaint(), with the latter doing most of the work while the former simply creates the PaintDC then calls DoPaint(). Making this change eliminates the above exception, although the wxGUI crashes shortly afterwards (in Gs_loadmap_as_short(), AFAICT).
PS: I set the "component" field to wxGUI; is NVIZ for the Tcl/Tk NVIZ or for either version?