From c731eedeaf1c24e5c4444467c29510e091349ff1 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Sun, 18 Feb 2024 13:36:37 +0100 Subject: [PATCH 1/4] Use memmove instead of memcpy as the blocks overlap. --- source/frontend/StarVoice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/frontend/StarVoice.cpp b/source/frontend/StarVoice.cpp index 168d23b..68b83ae 100644 --- a/source/frontend/StarVoice.cpp +++ b/source/frontend/StarVoice.cpp @@ -433,7 +433,7 @@ void Voice::update(float dt, PositionalAttenuationFunction positionalAttenuation speaker->channelVolumes = Vec2F::filled(1.0f); auto& dbHistory = speaker->dbHistory; - memcpy(&dbHistory[1], &dbHistory[0], (dbHistory.size() - 1) * sizeof(float)); + memmove(&dbHistory[1], &dbHistory[0], (dbHistory.size() - 1) * sizeof(float)); dbHistory[0] = speaker->decibelLevel; float smoothDb = 0.0f; for (float dB : dbHistory) From 86106b06d60fb7811e271b2299a65a5ecf68620e Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Mon, 19 Feb 2024 14:13:15 +0100 Subject: [PATCH 2/4] Add StarFormat.h include to fix test compilation on UNIX Linker otherwise can't find a specialized template instance for strf() in a test. Adding the include file will locally generate the missing specialization. --- source/core/StarStaticVector.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/core/StarStaticVector.hpp b/source/core/StarStaticVector.hpp index 3a4a7cc..18ddaae 100644 --- a/source/core/StarStaticVector.hpp +++ b/source/core/StarStaticVector.hpp @@ -2,6 +2,7 @@ #define STAR_STATIC_VECTOR_HPP #include "StarException.hpp" +#include "StarFormat.hpp" namespace Star { From 42fc1d6714036a2814f1e6ab293eaa0009320ef4 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Mon, 19 Feb 2024 20:47:58 +0100 Subject: [PATCH 3/4] Fixed a memory leak in Image::readPngMetadata() The memory allocated by png_create_read_struct() was not freed before exiting the function, wasting lots of memory over time. --- source/core/StarImage.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/core/StarImage.cpp b/source/core/StarImage.cpp index 183b00a..f59765a 100644 --- a/source/core/StarImage.cpp +++ b/source/core/StarImage.cpp @@ -184,6 +184,8 @@ tuple Image::readPngMetadata(IODevicePtr device) { channels += 1; } + png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); + Vec2U imageSize{img_width, img_height}; PixelFormat pixelFormat = channels == 3 ? PixelFormat::RGB24 : PixelFormat::RGBA32; From d0099a6d790b66f21e4e266e569d64fb82fb0a81 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Mon, 19 Feb 2024 23:29:39 +0100 Subject: [PATCH 4/4] Fixed some uninitialized members May have caused undefined behavior in few cases, as most of the fixed members were used before being initialized. --- source/application/StarRenderer_opengl20.hpp | 2 +- source/base/StarCellularLighting.cpp | 9 ++++-- source/base/StarCellularLighting.hpp | 2 +- source/frontend/StarCinematic.cpp | 5 ++- source/frontend/StarCinematic.hpp | 32 ++++++++++---------- source/frontend/StarMainInterface.cpp | 30 ++++++------------ source/frontend/StarMainInterface.hpp | 20 ++++++------ source/game/StarSystemWorldServerThread.cpp | 8 +++-- source/game/StarSystemWorldServerThread.hpp | 6 ++-- source/game/StarWorldServer.hpp | 2 +- source/rendering/StarEnvironmentPainter.hpp | 2 +- 11 files changed, 56 insertions(+), 62 deletions(-) diff --git a/source/application/StarRenderer_opengl20.hpp b/source/application/StarRenderer_opengl20.hpp index 4d917d5..cbf3924 100644 --- a/source/application/StarRenderer_opengl20.hpp +++ b/source/application/StarRenderer_opengl20.hpp @@ -143,7 +143,7 @@ private: HashSet usedTextures; List vertexBuffers; - bool useMultiTexturing; + bool useMultiTexturing{true}; }; struct EffectParameter { diff --git a/source/base/StarCellularLighting.cpp b/source/base/StarCellularLighting.cpp index 49c5676..e4fe8dd 100644 --- a/source/base/StarCellularLighting.cpp +++ b/source/base/StarCellularLighting.cpp @@ -2,8 +2,13 @@ namespace Star { -CellularLightingCalculator::CellularLightingCalculator(bool monochrome) { - setMonochrome(monochrome); +CellularLightingCalculator::CellularLightingCalculator(bool monochrome) + : m_monochrome(monochrome) +{ + if (monochrome) + m_lightArray.setRight(ScalarCellularLightArray()); + else + m_lightArray.setLeft(ColoredCellularLightArray()); } void CellularLightingCalculator::setMonochrome(bool monochrome) { diff --git a/source/base/StarCellularLighting.hpp b/source/base/StarCellularLighting.hpp index 30aa489..c82032c 100644 --- a/source/base/StarCellularLighting.hpp +++ b/source/base/StarCellularLighting.hpp @@ -17,7 +17,7 @@ namespace Star { // individually. class CellularLightingCalculator { public: - CellularLightingCalculator(bool monochrome = false); + explicit CellularLightingCalculator(bool monochrome = false); typedef ColoredCellularLightArray::Cell Cell; diff --git a/source/frontend/StarCinematic.cpp b/source/frontend/StarCinematic.cpp index 40fc8d1..7b095a6 100644 --- a/source/frontend/StarCinematic.cpp +++ b/source/frontend/StarCinematic.cpp @@ -12,7 +12,6 @@ const float vWidth = 960.0f; const float vHeight = 540.0f; Cinematic::Cinematic() { - m_completionTime = 0; m_completable = false; m_suppressInput = false; } @@ -342,7 +341,7 @@ float Cinematic::currentTimecode() const { Cinematic::PanelValues Cinematic::determinePanelValues(PanelPtr panel, float timecode) { if (panel->endTime != 0) { if (timecode > panel->endTime) { - Cinematic::PanelValues result; + Cinematic::PanelValues result{}; result.alpha = 0; return result; } @@ -350,7 +349,7 @@ Cinematic::PanelValues Cinematic::determinePanelValues(PanelPtr panel, float tim if (panel->startTime != 0) { if (timecode < panel->startTime) { - Cinematic::PanelValues result; + Cinematic::PanelValues result{}; result.alpha = 0; return result; } else { diff --git a/source/frontend/StarCinematic.hpp b/source/frontend/StarCinematic.hpp index 96f40e7..a86523a 100644 --- a/source/frontend/StarCinematic.hpp +++ b/source/frontend/StarCinematic.hpp @@ -109,33 +109,33 @@ private: // these include the time for background fades so they may not reflect the completion timecode Clock m_timer; - float m_completionTime; + float m_completionTime{}; Maybe m_backgroundColor; - float m_backgroundFadeTime; + float m_backgroundFadeTime{}; - float m_cameraZoom; - Vec2F m_cameraPan; + float m_cameraZoom{1.0f}; + Vec2F m_cameraPan{}; - float m_drawableScale; - Vec2F m_drawableTranslation; - Vec2F m_windowSize; - RectI m_scissorRect; + float m_drawableScale{1.0f}; + Vec2F m_drawableTranslation{}; + Vec2F m_windowSize{}; + RectI m_scissorRect{}; - bool m_scissor; - bool m_letterbox; + bool m_scissor{true}; + bool m_letterbox{true}; PlayerPtr m_player; - Vec2F m_offset; + Vec2F m_offset{}; - bool m_skippable; - bool m_suppressInput; + bool m_skippable{true}; + bool m_suppressInput{false}; - bool m_muteSfx; - bool m_muteMusic; + bool m_muteSfx{false}; + bool m_muteMusic{false}; - bool m_completable; + bool m_completable{false}; }; } diff --git a/source/frontend/StarMainInterface.cpp b/source/frontend/StarMainInterface.cpp index a0ed3ae..b7c93d1 100644 --- a/source/frontend/StarMainInterface.cpp +++ b/source/frontend/StarMainInterface.cpp @@ -65,24 +65,14 @@ GuiMessage::GuiMessage() : message(), cooldown(), springState() {} GuiMessage::GuiMessage(String const& message, float cooldown, float spring) : message(message), cooldown(cooldown), springState(spring) {} -MainInterface::MainInterface(UniverseClientPtr client, WorldPainterPtr painter, CinematicPtr cinematicOverlay) { - m_state = Running; - - m_guiContext = GuiContext::singletonPtr(); - - m_client = client; - m_worldPainter = painter; - m_cinematicOverlay = cinematicOverlay; - - m_disableHud = false; - - m_cursorScreenPos = Vec2I(); - m_state = Running; - - m_config = MainInterfaceConfig::loadFromAssets(); - - m_containerInteractor = make_shared(); - +MainInterface::MainInterface(UniverseClientPtr client, WorldPainterPtr painter, CinematicPtr cinematicOverlay) + : m_guiContext(GuiContext::singletonPtr()) + , m_config(MainInterfaceConfig::loadFromAssets()) + , m_client(std::move(client)) + , m_worldPainter(std::move(painter)) + , m_cinematicOverlay(std::move(cinematicOverlay)) + , m_containerInteractor(make_shared()) +{ GuiReader itemSlotReader; m_cursorItem = convert(itemSlotReader.makeSingle("cursorItemSlot", m_config->cursorItemSlot)); @@ -90,9 +80,7 @@ MainInterface::MainInterface(UniverseClientPtr client, WorldPainterPtr painter, m_debugSpatialClearTimer = GameTimer(m_config->debugSpatialClearTime); m_debugMapClearTimer = GameTimer(m_config->debugMapClearTime); - m_debugTextRect = RectF::null(); - m_lastMouseoverTarget = NullEntityId; m_stickyTargetingTimer = GameTimer(m_config->monsterHealthBarTime); m_inventoryWindow = make_shared(this, m_client->mainPlayer(), m_containerInteractor); @@ -183,7 +171,7 @@ MainInterface::MainInterface(UniverseClientPtr client, WorldPainterPtr painter, m_paneManager.registerPane(MainInterfacePanes::PlanetText, PaneLayer::Hud, planetName); m_nameplatePainter = make_shared(); - m_questIndicatorPainter = make_shared(client); + m_questIndicatorPainter = make_shared(m_client); m_chatBubbleManager = make_shared(); m_paneManager.displayRegisteredPane(MainInterfacePanes::ActionBar); diff --git a/source/frontend/StarMainInterface.hpp b/source/frontend/StarMainInterface.hpp index adba4e6..91a63ab 100644 --- a/source/frontend/StarMainInterface.hpp +++ b/source/frontend/StarMainInterface.hpp @@ -154,11 +154,11 @@ private: void displayScriptPane(ScriptPanePtr& scriptPane, EntityId sourceEntity); - GuiContext* m_guiContext; + GuiContext* m_guiContext{nullptr}; MainInterfaceConfigConstPtr m_config; InterfaceCursor m_cursor; - RunningState m_state; + RunningState m_state{Running}; UniverseClientPtr m_client; WorldPainterPtr m_worldPainter; @@ -192,7 +192,7 @@ private: WirePanePtr m_wireInterface; ActionBarPtr m_actionBar; - Vec2I m_cursorScreenPos; + Vec2I m_cursorScreenPos{}; ItemSlotWidgetPtr m_cursorItem; Maybe m_cursorTooltip; @@ -201,29 +201,29 @@ private: GameTimer m_debugSpatialClearTimer; GameTimer m_debugMapClearTimer; - RectF m_debugTextRect; + RectF m_debugTextRect{RectF::null()}; NameplatePainterPtr m_nameplatePainter; QuestIndicatorPainterPtr m_questIndicatorPainter; ChatBubbleManagerPtr m_chatBubbleManager; - bool m_disableHud; + bool m_disableHud{false}; String m_lastCommand; LinkedList m_messages; HashMap> m_itemDropMessages; - unsigned m_messageOverflow; + unsigned m_messageOverflow{}; GuiMessagePtr m_overflowMessage; List>> m_queuedJoinRequests; - EntityId m_lastMouseoverTarget; + EntityId m_lastMouseoverTarget{NullEntityId}; GameTimer m_stickyTargetingTimer; - int m_portraitScale; + int m_portraitScale{}; - EntityId m_specialDamageBarTarget; - float m_specialDamageBarValue; + EntityId m_specialDamageBarTarget{NullEntityId}; + float m_specialDamageBarValue{}; ContainerInteractorPtr m_containerInteractor; }; diff --git a/source/game/StarSystemWorldServerThread.cpp b/source/game/StarSystemWorldServerThread.cpp index fb5cea5..55488e0 100644 --- a/source/game/StarSystemWorldServerThread.cpp +++ b/source/game/StarSystemWorldServerThread.cpp @@ -5,9 +5,11 @@ namespace Star { SystemWorldServerThread::SystemWorldServerThread(Vec3I const& location, SystemWorldServerPtr systemWorld, String storageFile) - : Thread(strf("SystemWorldServer: {}", location)), m_stop(false), m_storageFile(storageFile) { - m_systemLocation = location; - m_systemWorld = move(systemWorld); + : Thread(strf("SystemWorldServer: {}", location)) + , m_systemLocation(location) + , m_systemWorld(move(systemWorld)) + , m_storageFile(storageFile) +{ } SystemWorldServerThread::~SystemWorldServerThread() { diff --git a/source/game/StarSystemWorldServerThread.hpp b/source/game/StarSystemWorldServerThread.hpp index f81749e..6e09260 100644 --- a/source/game/StarSystemWorldServerThread.hpp +++ b/source/game/StarSystemWorldServerThread.hpp @@ -48,9 +48,9 @@ private: Vec3I m_systemLocation; SystemWorldServerPtr m_systemWorld; - atomic m_stop; - float m_periodicStorage; - bool m_triggerStorage; + atomic m_stop{false}; + float m_periodicStorage{300.0f}; + bool m_triggerStorage{ false}; String m_storageFile; shared_ptr> m_pause; diff --git a/source/game/StarWorldServer.hpp b/source/game/StarWorldServer.hpp index 24436b6..ff93c81 100644 --- a/source/game/StarWorldServer.hpp +++ b/source/game/StarWorldServer.hpp @@ -362,7 +362,7 @@ private: StringMap m_scriptContexts; WorldGeometry m_geometry; - uint64_t m_currentStep; + uint64_t m_currentStep{}; mutable CellularLightIntensityCalculator m_lightIntensityCalculator; SkyPtr m_sky; diff --git a/source/rendering/StarEnvironmentPainter.hpp b/source/rendering/StarEnvironmentPainter.hpp index 7367095..d439acd 100644 --- a/source/rendering/StarEnvironmentPainter.hpp +++ b/source/rendering/StarEnvironmentPainter.hpp @@ -69,7 +69,7 @@ private: double m_timer; PerlinF m_rayPerlin; - uint64_t m_starsHash; + uint64_t m_starsHash{}; List m_starTextures; shared_ptr>> m_starGenerator; List, double>>> m_debrisGenerators;