From 07acd9375b0612adeb691ecab5438e87794cf4a1 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 24 Jan 2017 02:28:32 +0100 Subject: [PATCH] The memset antipattern cannot be used on classes with a virtual table --- src/swrenderer/things/r_particle.cpp | 1 - src/swrenderer/things/r_particle.h | 10 +++--- src/swrenderer/things/r_playersprite.cpp | 1 - src/swrenderer/things/r_sprite.cpp | 1 - src/swrenderer/things/r_sprite.h | 10 +++--- src/swrenderer/things/r_visiblesprite.h | 43 ++++++++++++------------ src/swrenderer/things/r_voxel.h | 14 ++++---- src/swrenderer/things/r_wallsprite.h | 4 +-- 8 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/swrenderer/things/r_particle.cpp b/src/swrenderer/things/r_particle.cpp index 510d05b7f6..ed32c2a005 100644 --- a/src/swrenderer/things/r_particle.cpp +++ b/src/swrenderer/things/r_particle.cpp @@ -179,7 +179,6 @@ namespace swrenderer // store information in a vissprite RenderParticle *vis = RenderMemory::NewObject(); - memset(vis, 0, sizeof(*vis)); vis->CurrentPortalUniq = renderportal->CurrentPortalUniq; vis->heightsec = heightsec; diff --git a/src/swrenderer/things/r_particle.h b/src/swrenderer/things/r_particle.h index 244d1a8eee..2115220749 100644 --- a/src/swrenderer/things/r_particle.h +++ b/src/swrenderer/things/r_particle.h @@ -32,11 +32,11 @@ namespace swrenderer private: void DrawMaskedSegsBehindParticle(); - fixed_t xscale; - fixed_t startfrac; // horizontal position of x1 - int y1, y2; + fixed_t xscale = 0; + fixed_t startfrac = 0; // horizontal position of x1 + int y1 = 0, y2 = 0; - uint32_t Translation; - uint32_t FillColor; + uint32_t Translation = 0; + uint32_t FillColor = 0; }; } diff --git a/src/swrenderer/things/r_playersprite.cpp b/src/swrenderer/things/r_playersprite.cpp index 4cba801b7e..a259ff1b3f 100644 --- a/src/swrenderer/things/r_playersprite.cpp +++ b/src/swrenderer/things/r_playersprite.cpp @@ -273,7 +273,6 @@ namespace swrenderer // store information in a vissprite RenderSprite *vis = &avis[vispspindex]; - memset(vis, 0, sizeof(*vis)); vis->renderflags = owner->renderflags; vis->floorclip = 0; diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index 3776540434..d237348f49 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -157,7 +157,6 @@ namespace swrenderer // store information in a vissprite RenderSprite *vis = RenderMemory::NewObject(); - memset(vis, 0, sizeof(*vis)); vis->CurrentPortalUniq = renderportal->CurrentPortalUniq; vis->xscale = FLOAT2FIXED(xscale); diff --git a/src/swrenderer/things/r_sprite.h b/src/swrenderer/things/r_sprite.h index 595a5d2a83..86462786ee 100644 --- a/src/swrenderer/things/r_sprite.h +++ b/src/swrenderer/things/r_sprite.h @@ -26,12 +26,12 @@ namespace swrenderer void Render(short *cliptop, short *clipbottom, int minZ, int maxZ) override; private: - fixed_t xscale; - fixed_t startfrac; // horizontal position of x1 - fixed_t xiscale; // negative if flipped + fixed_t xscale = 0; + fixed_t startfrac = 0; // horizontal position of x1 + fixed_t xiscale = 0; // negative if flipped - uint32_t Translation; - uint32_t FillColor; + uint32_t Translation = 0; + uint32_t FillColor = 0; friend class RenderPlayerSprite; // To do: detach sprite from playersprite! }; diff --git a/src/swrenderer/things/r_visiblesprite.h b/src/swrenderer/things/r_visiblesprite.h index 73b84ebae8..bfe8a84e0b 100644 --- a/src/swrenderer/things/r_visiblesprite.h +++ b/src/swrenderer/things/r_visiblesprite.h @@ -26,6 +26,7 @@ namespace swrenderer class VisibleSprite { public: + VisibleSprite() { RenderStyle = STYLE_Normal; } virtual ~VisibleSprite() { } void Render(); @@ -45,38 +46,38 @@ namespace swrenderer virtual void Render(short *cliptop, short *clipbottom, int minZ, int maxZ) = 0; - FTexture *pic; + FTexture *pic = nullptr; - short x1, x2; - float gzb, gzt; // global bottom / top for silhouette clipping + short x1 = 0, x2 = 0; + float gzb = 0.0f, gzt = 0.0f; // global bottom / top for silhouette clipping - double floorclip; + double floorclip = 0.0; - double texturemid; // floorclip - float yscale; // voxel and floorclip + double texturemid = 0.0; // floorclip + float yscale = 0.0f; // voxel and floorclip - sector_t *heightsec; // height sector for underwater/fake ceiling - WaterFakeSide FakeFlatStat; // which side of fake/floor ceiling sprite is on + sector_t *heightsec = nullptr; // height sector for underwater/fake ceiling + WaterFakeSide FakeFlatStat = WaterFakeSide::Center; // which side of fake/floor ceiling sprite is on - F3DFloor *fakefloor; // 3d floor clipping - F3DFloor *fakeceiling; + F3DFloor *fakefloor = nullptr; // 3d floor clipping + F3DFloor *fakeceiling = nullptr; - FVector3 gpos; // origin in world coordinates - sector_t *sector; // sector this sprite is in + FVector3 gpos = { 0.0f, 0.0f, 0.0f }; // origin in world coordinates + sector_t *sector = nullptr; // sector this sprite is in // Light shared calculation? - int ColormapNum; // Which colormap is rendered - FSWColormap *BaseColormap; // Base colormap used together with ColormapNum - float Alpha; + int ColormapNum = 0; // Which colormap is rendered + FSWColormap *BaseColormap = nullptr; // Base colormap used together with ColormapNum + float Alpha = 0.0f; FRenderStyle RenderStyle; - bool foggy; - short renderflags; + bool foggy = false; + short renderflags = 0; - float depth; // Sort (draw segments), also light + float depth = 0.0f; // Sort (draw segments), also light - float deltax, deltay; // Sort (2d/voxel version) - float idepth; // Sort (non-voxel version) + float deltax = 0.0f, deltay = 0.0f; // Sort (2d/voxel version) + float idepth = 0.0f; // Sort (non-voxel version) - int CurrentPortalUniq; // to identify the portal that this thing is in. used for clipping. + int CurrentPortalUniq = 0; // to identify the portal that this thing is in. used for clipping. }; } diff --git a/src/swrenderer/things/r_voxel.h b/src/swrenderer/things/r_voxel.h index d237d9b66e..ae41ea7ee3 100644 --- a/src/swrenderer/things/r_voxel.h +++ b/src/swrenderer/things/r_voxel.h @@ -65,17 +65,17 @@ namespace swrenderer private: struct posang { - FVector3 vpos; // view origin - FAngle vang; // view angle + FVector3 vpos = { 0.0f, 0.0f, 0.0f }; // view origin + FAngle vang = { 0.0f }; // view angle }; posang pa; - DAngle Angle; - fixed_t xscale; - FVoxel *voxel; + DAngle Angle = { 0.0 }; + fixed_t xscale = 0; + FVoxel *voxel = nullptr; - uint32_t Translation; - uint32_t FillColor; + uint32_t Translation = 0; + uint32_t FillColor = 0; enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 }; diff --git a/src/swrenderer/things/r_wallsprite.h b/src/swrenderer/things/r_wallsprite.h index 2123948669..a68454b2e4 100644 --- a/src/swrenderer/things/r_wallsprite.h +++ b/src/swrenderer/things/r_wallsprite.h @@ -30,7 +30,7 @@ namespace swrenderer static void DrawColumn(int x, FTexture *WallSpriteTile, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip); FWallCoords wallc; - uint32_t Translation; - uint32_t FillColor; + uint32_t Translation = 0; + uint32_t FillColor = 0; }; }