[GRASS-dev] [GRASS GIS] #1141: GLWindow.OnPaint() broken on Windows

#1141: GLWindow.OnPaint() broken on Windows
--------------------+-------------------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz | Platform: MSWindows XP
      Cpu: All |
--------------------+-------------------------------------------------------
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?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
--------------------+-------------------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz | Platform: MSWindows XP
      Cpu: All |
--------------------+-------------------------------------------------------

Comment(by martinl):

Replying to [ticket:1141 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.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------
Changes (by martinl):

* cc: martinl (added)
  * keywords: nviz => nviz, wingrass

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------

Comment(by glynn):

Replying to [ticket:1141 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1141#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------

Comment(by hamish):

Replying to [comment:1 martinl]:
> Replying to [ticket:1141 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" :slight_smile:

Hamish

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1141#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------

Comment(by martinl):

Replying to [comment:4 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" :slight_smile:

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

Martin

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------

Comment(by martinl):

Replying to [comment:5 martinl]:
> > (and fwiw "Tcl/Tk" not "TCL/TK" :slight_smile:
>
> right, http://en.wikipedia.org/wiki/Tcl/tk - renamed.

now

https://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

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------

Comment(by hamish):

Replying to [comment:5 martinl]:
> Replying to [comment:4 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" :slight_smile:
>
> 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.. :slight_smile:

now back to your regularly scheduled bug report,
Hamish

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------

Comment(by hellik):

Replying to [comment:3 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

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------

Comment(by hellik):

Replying to [comment:8 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

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
----------------------------+-----------------------------------------------
Reporter: glynn | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: wxGUI | Version: unspecified
Keywords: nviz, wingrass | Platform: MSWindows XP
      Cpu: All |
----------------------------+-----------------------------------------------
Changes (by hellik):

  * milestone: 6.4.0 => 7.0.0

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
---------------------------+------------------------------------------------
  Reporter: glynn | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: wxGUI | Version: unspecified
Resolution: fixed | Keywords: nviz, wingrass
  Platform: MSWindows XP | Cpu: All
---------------------------+------------------------------------------------
Changes (by annakrat):

  * status: new => closed
  * resolution: => fixed

Comment:

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

Replying to [comment:9 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

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:11&gt;
GRASS GIS <http://grass.osgeo.org>

#1141: GLWindow.OnPaint() broken on Windows
---------------------------+------------------------------------------------
  Reporter: glynn | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: wxGUI | Version: unspecified
Resolution: fixed | Keywords: nviz, wingrass
  Platform: MSWindows XP | Cpu: All
---------------------------+------------------------------------------------

Comment(by hellik):

Replying to [comment:11 annakrat]:
>
> The GUI crash should be fixed (r53246).

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

thanks.

Helmut

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1141#comment:12&gt;
GRASS GIS <http://grass.osgeo.org>