]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
radiant/camwindow, radiant/xywindow: Fix use of uninitialized values 176/head
authorAntoine Fontaine <antoine.fontaine@epfl.ch>
Tue, 23 Mar 2021 01:54:50 +0000 (02:54 +0100)
committerAntoine Fontaine <antoine.fontaine@epfl.ch>
Tue, 23 Mar 2021 12:34:41 +0000 (13:34 +0100)
radiant/camwindow.cpp
radiant/xywindow.cpp
radiant/xywindow.h

index d3dbf3c5828c8ecb562ecf3497fa0cdb26e34513..f157b87e2bd811cfe997a7b6f0284bb6449f08b3 100644 (file)
@@ -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 ),
index ab1e8ee9d823d3b338f14383552760086b5bf35b..35d491701aa9a318ee3cfa822aa852a02b302f81 100644 (file)
@@ -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<XYWnd, void(), &XYWnd_Update>( *this ) );
        AddCameraMovedCallback( ReferenceCaller<XYWnd, void(), &XYWnd_CameraMoved>( *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<float>( m_nWidth / 2 );
        m_projection[5] = 1.0f / static_cast<float>( 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 );
+       }
 }
 
 /*
index ee434833bb05f3e950bb7360372a09b72213c1e5..ac059329518178de2d63c32843579c56352f6be8 100644 (file)
@@ -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;