Skip to content

Commit

Permalink
ShowBase: Fixed crash when want-render2dp is False
Browse files Browse the repository at this point in the history
        - Fixed crash in ShowBase when want-render2dp setting
        is set to 0(False).

Signed-off-by: deflected <deflected@users.noreply.github.com>
  • Loading branch information
deflected authored and rdb committed Dec 4, 2017
1 parent 7a46b2c commit bdd53d6
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions direct/src/showbase/ShowBase.py
Expand Up @@ -968,7 +968,9 @@ def openMainWindow(self, *args, **kw):
if isinstance(self.win, GraphicsWindow):
self.setupMouse(self.win)
self.makeCamera2d(self.win)
self.makeCamera2dp(self.win)

if self.wantRender2dp:
self.makeCamera2dp(self.win)

if oldLens != None:
# Restore the previous lens properties.
Expand Down Expand Up @@ -1559,9 +1561,11 @@ def setupMouse(self, win, fMultiWin=False):

# Tell the gui system about our new mouse watcher.
self.aspect2d.node().setMouseWatcher(mw.node())
self.aspect2dp.node().setMouseWatcher(mw.node())
self.pixel2d.node().setMouseWatcher(mw.node())
self.pixel2dp.node().setMouseWatcher(mw.node())
if self.wantRender2dp:
self.aspect2dp.node().setMouseWatcher(mw.node())
self.pixel2dp.node().setMouseWatcher(mw.node())

mw.node().addRegion(PGMouseWatcherBackground())

return self.buttonThrowers[0]
Expand Down Expand Up @@ -2729,7 +2733,8 @@ def windowEvent(self, win):
xsize, ysize = self.getSize()
if xsize > 0 and ysize > 0:
self.pixel2d.setScale(2.0 / xsize, 1.0, 2.0 / ysize)
self.pixel2dp.setScale(2.0 / xsize, 1.0, 2.0 / ysize)
if self.wantRender2dp:
self.pixel2dp.setScale(2.0 / xsize, 1.0, 2.0 / ysize)

def adjustWindowAspectRatio(self, aspectRatio):
""" This function is normally called internally by
Expand All @@ -2753,11 +2758,12 @@ class that has redefined these. """
self.a2dLeft = -1
self.a2dRight = 1.0
# Don't forget 2dp
self.aspect2dp.setScale(1.0, aspectRatio, aspectRatio)
self.a2dpTop = 1.0 / aspectRatio
self.a2dpBottom = - 1.0 / aspectRatio
self.a2dpLeft = -1
self.a2dpRight = 1.0
if self.wantRender2dp:
self.aspect2dp.setScale(1.0, aspectRatio, aspectRatio)
self.a2dpTop = 1.0 / aspectRatio
self.a2dpBottom = - 1.0 / aspectRatio
self.a2dpLeft = -1
self.a2dpRight = 1.0

else:
# If the window is WIDE, lets expand the left and right
Expand All @@ -2767,11 +2773,12 @@ class that has redefined these. """
self.a2dLeft = -aspectRatio
self.a2dRight = aspectRatio
# Don't forget 2dp
self.aspect2dp.setScale(1.0 / aspectRatio, 1.0, 1.0)
self.a2dpTop = 1.0
self.a2dpBottom = -1.0
self.a2dpLeft = -aspectRatio
self.a2dpRight = aspectRatio
if self.wantRender2dp:
self.aspect2dp.setScale(1.0 / aspectRatio, 1.0, 1.0)
self.a2dpTop = 1.0
self.a2dpBottom = -1.0
self.a2dpLeft = -aspectRatio
self.a2dpRight = aspectRatio

# Reposition the aspect2d marker nodes
self.a2dTopCenter.setPos(0, 0, self.a2dTop)
Expand All @@ -2793,15 +2800,16 @@ class that has redefined these. """
self.a2dBottomRightNs.setPos(self.a2dRight, 0, self.a2dBottom)

# Reposition the aspect2dp marker nodes
self.a2dpTopCenter.setPos(0, 0, self.a2dpTop)
self.a2dpBottomCenter.setPos(0, 0, self.a2dpBottom)
self.a2dpLeftCenter.setPos(self.a2dpLeft, 0, 0)
self.a2dpRightCenter.setPos(self.a2dpRight, 0, 0)

self.a2dpTopLeft.setPos(self.a2dpLeft, 0, self.a2dpTop)
self.a2dpTopRight.setPos(self.a2dpRight, 0, self.a2dpTop)
self.a2dpBottomLeft.setPos(self.a2dpLeft, 0, self.a2dpBottom)
self.a2dpBottomRight.setPos(self.a2dpRight, 0, self.a2dpBottom)
if self.wantRender2dp:
self.a2dpTopCenter.setPos(0, 0, self.a2dpTop)
self.a2dpBottomCenter.setPos(0, 0, self.a2dpBottom)
self.a2dpLeftCenter.setPos(self.a2dpLeft, 0, 0)
self.a2dpRightCenter.setPos(self.a2dpRight, 0, 0)

self.a2dpTopLeft.setPos(self.a2dpLeft, 0, self.a2dpTop)
self.a2dpTopRight.setPos(self.a2dpRight, 0, self.a2dpTop)
self.a2dpBottomLeft.setPos(self.a2dpLeft, 0, self.a2dpBottom)
self.a2dpBottomRight.setPos(self.a2dpRight, 0, self.a2dpBottom)

# If anybody needs to update their GUI, put a callback on this event
messenger.send("aspectRatioChanged")
Expand Down

0 comments on commit bdd53d6

Please sign in to comment.