Opened 14 years ago

Closed 12 years ago

Last modified 12 years ago

#1141 closed defect (fixed)

GLWindow.OnPaint() broken on Windows

Reported by: glynn Owned by: grass-dev@…
Priority: normal Milestone: 7.0.0
Component: wxGUI Version: unspecified
Keywords: nviz, wingrass Cc: martinl
CPU: All Platform: MSWindows XP

Description

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?

Attachments (1)

WinGrass7_nviz_26082010_220351.png (43.1 KB ) - added by hellik 14 years ago.

Download all attachments as: .zip

Change History (13)

in reply to:  description ; comment:1 by martinl, 14 years ago

Replying to glynn:

PS: I set the "component" field to wxGUI; is NVIZ for the Tcl/Tk NVIZ or for either version?

this component is related to TCL/TK-based NVIZ. I have renamed it to "TCL/TK NVIZ" to avoid confusion.

comment:2 by martinl, 14 years ago

Cc: martinl added
Keywords: wingrass added

in reply to:  description ; comment:3 by glynn, 14 years ago

Replying to glynn:

although the wxGUI crashes shortly afterwards (in Gs_loadmap_as_short(), AFAICT).

FWIW, this should be fixed by r43279. fmode.o doesn't help with libraries which are loaded at run-time (e.g. via ctypes), which meant that open() was opening files in text mode, resulting in EOF at the first Ctrl-Z byte (\x1a), as well as performing CRLF->LF conversion.

With the OnPaint/DoPaint change (r43280), wxNviz now works (for me) on Windows, although using it does result in Python crashing when you quit the GUI.

in reply to:  1 ; comment:4 by hamish, 14 years ago

Replying to martinl:

Replying to glynn:

PS: I set the "component" field to wxGUI; is NVIZ for the Tcl/Tk NVIZ or for either version?

this component is related to TCL/TK-based NVIZ. I have renamed it to "TCL/TK NVIZ" to avoid confusion.

Does that make any bugs tagged against the prior "NVIZ" now orphaned in the db, or do they follow? I had also thought to rename SWIG component -> ctypes, but stalled as I worried about this issue.

(and fwiw "Tcl/Tk" not "TCL/TK" :)

Hamish

in reply to:  4 ; comment:5 by martinl, 14 years ago

Replying to hamish:

Does that make any bugs tagged against the prior "NVIZ" now orphaned in the db, or do they follow? I had also thought to rename SWIG component -> ctypes, but stalled as I worried about this issue.

seems to follow, see e.g.

http://trac.osgeo.org/grass/query?status=assigned&status=new&status=reopened&component=TCL%2FTK+NVIZ&order=priority&col=id&col=summary&col=status&col=type&col=priority&col=milestone&col=component

(and fwiw "Tcl/Tk" not "TCL/TK" :)

right, http://en.wikipedia.org/wiki/Tcl/tk - renamed.

Martin

comment:7 by hamish, 14 years ago

Replying to martinl:

Replying to hamish:

Does that make any bugs tagged against the prior "NVIZ" now orphaned in the db, or do they follow? I had also thought to rename SWIG component -> ctypes, but stalled as I worried about this issue.

seems to follow, see e.g.

excellent. SWIG component now renamed to "Python ctypes" too. (it turns out there were only about 4 open+closed of those in total)

(and fwiw "Tcl/Tk" not "TCL/TK" :)

right, http://en.wikipedia.org/wiki/Tcl/tk - renamed.

& I guess technically it should be called nViz as it is short for the n-dimensional visualizer, but no need to fight the years of momentum.. :)

now back to your regularly scheduled bug report, Hamish

in reply to:  3 ; comment:8 by hellik, 14 years ago

Replying to glynn: [...]

With the OnPaint/DoPaint change (r43280), wxNviz now works (for me) on Windows, although using it does result in Python crashing when you quit the GUI.

see also ticket #1134

now tested with a self compiled wingrass7-installer at r43283, wxnviz is also working for me for the first time. there is no crashing by quit the GUI at my side.

Helmut

in reply to:  8 ; comment:9 by hellik, 14 years ago

Replying to hellik:

[...]there is no crashing by quit the GUI at my side.

I was to early, also a python crash by quit the GUI here.

and after switch back to the 2d-view-mode, there are relicts of the 3dview-mode buttons in the map layers tab (see screenshot)

Helmut

comment:10 by hellik, 13 years ago

Milestone: 6.4.07.0.0

in reply to:  9 ; comment:11 by annakrat, 12 years ago

Resolution: fixed
Status: newclosed

The OnPaint error is fixed now, so I'm closing the ticket.

Replying to hellik:

and after switch back to the 2d-view-mode, there are relicts of the 3dview-mode buttons in the map layers tab (see screenshot)

If this problem still exist, please open a new ticket. The GUI crash should be fixed (r53246).

Anna

in reply to:  11 comment:12 by hellik, 12 years ago

Replying to annakrat:

The GUI crash should be fixed (r53246).

tested with the osgeo4w-wingrass7-nightly build, no crash anymore by quitting the GUI.

thanks.

Helmut

Note: See TracTickets for help on using tickets.