From: Antoine Fontaine Date: Tue, 23 Mar 2021 01:54:50 +0000 (+0100) Subject: radiant/camwindow, radiant/xywindow: Fix use of uninitialized values X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=80bb5fdd23e124b4c4da8509634d95d1459e6a3b;p=xonotic%2Fnetradiant.git radiant/camwindow, radiant/xywindow: Fix use of uninitialized values --- diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index d3dbf3c5..f157b87e 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -171,7 +171,10 @@ struct camera_t origin( 0, 0, 0 ), angles( 0, 0, 0 ), color( 0, 0, 0 ), + projection( g_matrix4_identity ), + modelview( g_matrix4_identity ), movementflags( 0 ), + m_keycontrol_timer(), m_keymove_handler( 0 ), fieldOfView( 90.0f ), m_mouseMove( motionDelta, this ), diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index ab1e8ee9..35d49170 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -799,7 +799,8 @@ XYWnd::XYWnd() : m_parent( ui::null ), m_window_observer( NewWindowObserver() ), m_XORRectangle( m_gl_widget ), - m_chasemouse_handler( 0 ){ + m_chasemouse_handler( 0 ) { + m_bActive = false; m_buttonstate = 0; @@ -850,8 +851,11 @@ XYWnd::XYWnd() : Map_addValidCallback( g_map, DeferredDrawOnMapValidChangedCaller( m_deferredDraw ) ); - updateProjection(); - updateModelview(); + // This reconstruct=false argument is used to avoid a circular dependency + // between modelview and projection initialization and a valgrind complaint + updateProjection( false ); + updateModelview( false ); + m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight ); AddSceneChangeCallback( ReferenceCaller( *this ) ); AddCameraMovedCallback( ReferenceCaller( *this ) ); @@ -2110,7 +2114,7 @@ RenderStateFlags m_globalstate; Shader* m_state_selected; }; -void XYWnd::updateProjection(){ +void XYWnd::updateProjection( bool reconstruct ){ m_projection[0] = 1.0f / static_cast( m_nWidth / 2 ); m_projection[5] = 1.0f / static_cast( m_nHeight / 2 ); m_projection[10] = 1.0f / ( g_MaxWorldCoord * m_fScale ); @@ -2133,11 +2137,13 @@ void XYWnd::updateProjection(){ m_projection[15] = 1.0f; - m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight ); + if (reconstruct) { + m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight ); + } } // note: modelview matrix must have a uniform scale, otherwise strange things happen when rendering the rotation manipulator. -void XYWnd::updateModelview(){ +void XYWnd::updateModelview( bool reconstruct ){ int nDim1 = ( m_viewType == YZ ) ? 1 : 0; int nDim2 = ( m_viewType == XY ) ? 1 : 2; @@ -2193,7 +2199,9 @@ void XYWnd::updateModelview(){ m_modelview[3] = m_modelview[7] = m_modelview[11] = 0; m_modelview[15] = 1; - m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight ); + if (reconstruct) { + m_view.Construct( m_projection, m_modelview, m_nWidth, m_nHeight ); + } } /* diff --git a/radiant/xywindow.h b/radiant/xywindow.h index ee434833..ac059329 100644 --- a/radiant/xywindow.h +++ b/radiant/xywindow.h @@ -152,8 +152,8 @@ guint m_chasemouse_handler; void ChaseMouse(); bool chaseMouseMotion( int pointx, int pointy ); -void updateModelview(); -void updateProjection(); +void updateModelview(bool reconstruct = true); +void updateProjection(bool reconstruct = true); Matrix4 m_projection; Matrix4 m_modelview;