Skip to content

Commit

Permalink
Assorted initialization cleanup and similar, found by valgrind and wa…
Browse files Browse the repository at this point in the history
…rnings
  • Loading branch information
hrydgard committed Jan 30, 2023
1 parent 0f52954 commit b97749d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Common/Net/NetBuffer.cpp
Expand Up @@ -37,8 +37,9 @@ bool Buffer::FlushSocket(uintptr_t sock, double timeout, bool *cancelled) {
}
}
int sent = send(sock, &data_[pos], (int)(end - pos), MSG_NOSIGNAL);
// TODO: Do we need some retry logic here, instead of just giving up?
if (sent < 0) {
ERROR_LOG(IO, "FlushSocket failed");
ERROR_LOG(IO, "FlushSocket failed to send: %d", errno);
return false;
}
pos += sent;
Expand Down
1 change: 0 additions & 1 deletion Common/UI/PopupScreens.cpp
Expand Up @@ -343,7 +343,6 @@ void SliderFloatPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
edit_->SetTextColor(dc.theme->itemStyle.fgColor);
edit_->SetTextAlign(FLAG_DYNAMIC_ASCII);
edit_->OnTextChange.Handle(this, &SliderFloatPopupScreen::OnTextChange);
changing_ = false;
lin->Add(edit_);
if (!units_.empty())
lin->Add(new TextView(units_, new LinearLayoutParams(10.0f)))->SetTextColor(dc.theme->itemStyle.fgColor);
Expand Down
8 changes: 4 additions & 4 deletions Common/UI/PopupScreens.h
Expand Up @@ -99,7 +99,7 @@ class SliderPopupScreen : public PopupScreen {
class SliderFloatPopupScreen : public PopupScreen {
public:
SliderFloatPopupScreen(float *value, float minValue, float maxValue, const std::string &title, float step = 1.0f, const std::string &units = "", bool liveUpdate = false)
: PopupScreen(title, "OK", "Cancel"), units_(units), value_(value), originalValue_(*value), minValue_(minValue), maxValue_(maxValue), step_(step), changing_(false), liveUpdate_(liveUpdate) {}
: PopupScreen(title, "OK", "Cancel"), units_(units), value_(value), originalValue_(*value), minValue_(minValue), maxValue_(maxValue), step_(step), liveUpdate_(liveUpdate) {}
void CreatePopupContents(UI::ViewGroup *parent) override;

const char *tag() const override { return "SliderFloatPopup"; }
Expand All @@ -115,13 +115,13 @@ class SliderFloatPopupScreen : public PopupScreen {
UI::SliderFloat *slider_ = nullptr;
UI::TextEdit *edit_ = nullptr;
std::string units_ = nullptr;
float sliderValue_;
float originalValue_;
float sliderValue_ = 0.0f;
float originalValue_ = 0.0f;
float *value_;
float minValue_;
float maxValue_;
float step_;
bool changing_;
bool changing_ = false;
bool liveUpdate_;
};

Expand Down
8 changes: 6 additions & 2 deletions Common/UI/Screen.cpp
Expand Up @@ -202,7 +202,9 @@ void ScreenManager::sendMessage(const char *msg, const char *value) {
if (!strcmp(msg, "recreateviews"))
RecreateAllViews();
if (!strcmp(msg, "lost_focus")) {
TouchInput input;
TouchInput input{};
input.x = -50000.0f;
input.y = -50000.0f;
input.flags = TOUCH_RELEASE_ALL;
input.timestamp = time_now_d();
input.id = 0;
Expand Down Expand Up @@ -238,7 +240,9 @@ void ScreenManager::push(Screen *screen, int layerFlags) {

// Release touches and unfocus.
UI::SetFocusedView(nullptr);
TouchInput input;
TouchInput input{};
input.x = -50000.0f;
input.y = -50000.0f;
input.flags = TOUCH_RELEASE_ALL;
input.timestamp = time_now_d();
input.id = 0;
Expand Down
5 changes: 2 additions & 3 deletions Common/UI/UIScreen.cpp
Expand Up @@ -217,14 +217,13 @@ UI::EventReturn UIScreen::OnCancel(UI::EventParams &e) {
}

PopupScreen::PopupScreen(std::string title, std::string button1, std::string button2)
: box_(0), defaultButton_(nullptr), title_(title) {
: title_(title) {
auto di = GetI18NCategory("Dialog");
if (!button1.empty())
button1_ = di->T(button1.c_str());
if (!button2.empty())
button2_ = di->T(button2.c_str());

alpha_ = 0.0f;
alpha_ = 0.0f; // inherited
}

void PopupScreen::touch(const TouchInput &touch) {
Expand Down
4 changes: 2 additions & 2 deletions Common/UI/UIScreen.h
Expand Up @@ -98,7 +98,7 @@ class PopupScreen : public UIDialogScreen {

private:
UI::LinearLayout *box_;
UI::Button *defaultButton_;
UI::Button *defaultButton_ = nullptr;
std::string title_;
std::string button1_;
std::string button2_;
Expand All @@ -110,7 +110,7 @@ class PopupScreen : public UIDialogScreen {

int frames_ = 0;
int finishFrame_ = -1;
DialogResult finishResult_;
DialogResult finishResult_ = DR_CANCEL;
bool hasPopupOrigin_ = false;
Point popupOrigin_;
float offsetY_ = 0.0f;
Expand Down
6 changes: 3 additions & 3 deletions SDL/SDLMain.cpp
Expand Up @@ -1011,7 +1011,7 @@ int main(int argc, char *argv[]) {
case SDL_BUTTON_LEFT:
{
mouseDown = true;
TouchInput input;
TouchInput input{};
input.x = mx;
input.y = my;
input.flags = TOUCH_DOWN | TOUCH_MOUSE;
Expand Down Expand Up @@ -1065,7 +1065,7 @@ int main(int argc, char *argv[]) {
}
case SDL_MOUSEMOTION:
if (mouseDown) {
TouchInput input;
TouchInput input{};
input.x = mx;
input.y = my;
input.flags = TOUCH_MOVE | TOUCH_MOUSE;
Expand All @@ -1080,7 +1080,7 @@ int main(int argc, char *argv[]) {
case SDL_BUTTON_LEFT:
{
mouseDown = false;
TouchInput input;
TouchInput input{};
input.x = mx;
input.y = my;
input.flags = TOUCH_UP | TOUCH_MOUSE;
Expand Down
4 changes: 2 additions & 2 deletions UI/EmuScreen.cpp
Expand Up @@ -1315,7 +1315,7 @@ static void DrawFPS(UIContext *ctx, const Bounds &bounds) {
snprintf(fpsbuf, sizeof(fpsbuf), "%0.0f/%0.0f (%0.1f%%)", actual_fps, fps, vps / (59.94f / 100.0f));
} else {
if (g_Config.iShowStatusFlags & (int)ShowStatusFlags::FPS_COUNTER) {
snprintf(fpsbuf, sizeof(fpsbuf), "%s FPS: %0.1f", fpsbuf, actual_fps);
snprintf(fpsbuf, sizeof(fpsbuf), "FPS: %0.1f", actual_fps);
}
if (g_Config.iShowStatusFlags & (int)ShowStatusFlags::SPEED_COUNTER) {
snprintf(fpsbuf, sizeof(fpsbuf), "%s Speed: %0.1f%%", fpsbuf, vps / (59.94f / 100.0f));
Expand All @@ -1327,7 +1327,7 @@ static void DrawFPS(UIContext *ctx, const Bounds &bounds) {
snprintf(fpsbuf, sizeof(fpsbuf), "%s Battery: %d%%", fpsbuf, getCurrentBatteryCapacity());
}
#endif

ctx->Flush();
ctx->BindFontTexture();
ctx->Draw()->SetFontScale(0.7f, 0.7f);
Expand Down

0 comments on commit b97749d

Please sign in to comment.