Bug Summary

File:Source/Core/DolphinWX/Src/WiimoteConfigDiag.cpp
Location:line 52, column 3
Description:Function call argument is an uninitialized value

Annotated Source Code

1
2#include "WiimoteConfigDiag.h"
3#include "HW/Wiimote.h"
4#include "HW/WiimoteReal/WiimoteReal.h"
5#include "Frame.h"
6
7WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin)
8 : wxDialog(parent, -1, _("Dolphin Wiimote Configuration")wxGetTranslation(("Dolphin Wiimote Configuration")), wxDefaultPosition, wxDefaultSize)
9 , m_plugin(plugin)
10{
11 wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL);
12
13
14 // "Wiimotes" controls
15 wxStaticText* wiimote_label[4];
16 wxChoice* wiimote_source_ch[4];
17
18 for (unsigned int i = 0; i < 4; ++i)
1
Loop condition is true. Entering loop body
2
Assuming 'i' is >= 4
3
Loop condition is false. Execution jumps to the end of the function
19 {
20 wxString str;
21 str.Printf(_("Wiimote %i")wxGetTranslation(("Wiimote %i")), i + 1);
22
23 const wxString src_choices[] = { _("None")wxGetTranslation(("None")),
24 _("Emulated Wiimote")wxGetTranslation(("Emulated Wiimote")), _("Real Wiimote")wxGetTranslation(("Real Wiimote")), _("Hybrid Wiimote")wxGetTranslation(("Hybrid Wiimote")) };
25
26 // reserve four ids, so that we can calculate the index from the ids later on
27 // Stupid wx 2.8 doesn't support reserving sequential IDs, so we need to do that more complicated..
28 int source_ctrl_id = wxWindow::NewControlId();
29 m_wiimote_index_from_ctrl_id.insert(std::pair<wxWindowID, unsigned int>(source_ctrl_id, i));
30
31 int config_bt_id = wxWindow::NewControlId();
32 m_wiimote_index_from_conf_bt_id.insert(std::pair<wxWindowID, unsigned int>(config_bt_id, i));
33
34 wiimote_label[i] = new wxStaticText(this, wxID_ANY, str);
35 wiimote_source_ch[i] = new wxChoice(this, source_ctrl_id, wxDefaultPosition, wxDefaultSize, sizeof(src_choices)/sizeof(*src_choices), src_choices);
36 wiimote_source_ch[i]->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &WiimoteConfigDiag::SelectSource, this);
37 wiimote_configure_bt[i] = new wxButton(this, config_bt_id, _("Configure")wxGetTranslation(("Configure")));
38 wiimote_configure_bt[i]->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::ConfigEmulatedWiimote, this);
39
40 m_orig_wiimote_sources[i] = g_wiimote_sources[i];
41 wiimote_source_ch[i]->Select(m_orig_wiimote_sources[i]);
42 if (m_orig_wiimote_sources[i] != WIIMOTE_SRC_EMU && m_orig_wiimote_sources[i] != WIIMOTE_SRC_HYBRID)
43 wiimote_configure_bt[i]->Disable();
44 }
45
46
47 // "Wiimotes" layout
48 wxStaticBoxSizer* const wiimote_group = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Wiimotes")wxGetTranslation(("Wiimotes")));
49 wxFlexGridSizer* const wiimote_sizer = new wxFlexGridSizer(3, 5, 5);
50 for (unsigned int i = 0; i < 4; ++i)
4
Loop condition is true. Entering loop body
51 {
52 wiimote_sizer->Add(wiimote_label[i], 0, wxALIGN_CENTER_VERTICAL);
5
Function call argument is an uninitialized value
53 wiimote_sizer->Add(wiimote_source_ch[i], 0, wxALIGN_CENTER_VERTICAL);
54 wiimote_sizer->Add(wiimote_configure_bt[i]);
55 }
56 wiimote_group->Add(wiimote_sizer, 1, wxEXPAND, 5 );
57
58
59 // "Real wiimotes" controls
60 wxButton* const refresh_btn = new wxButton(this, -1, _("Refresh")wxGetTranslation(("Refresh")), wxDefaultPosition);
61 refresh_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::RefreshRealWiimotes, this);
62
63 wxStaticBoxSizer* const real_wiimotes_group = new wxStaticBoxSizer(wxVERTICAL, this, _("Real Wiimotes")wxGetTranslation(("Real Wiimotes")));
64
65 wxBoxSizer* const real_wiimotes_sizer = new wxBoxSizer(wxHORIZONTAL);
66
67 if (!WiimoteReal::g_wiimote_scanner.IsReady())
68 real_wiimotes_group->Add(new wxStaticText(this, -1, _("A supported bluetooth device could not be found.\n"wxGetTranslation(("A supported bluetooth device could not be found.\n"
"You must manually connect your wiimotes."))
69 "You must manually connect your wiimotes.")wxGetTranslation(("A supported bluetooth device could not be found.\n"
"You must manually connect your wiimotes."))
), 0, wxALIGN_CENTER | wxALL, 5);
70
71 wxCheckBox* const continuous_scanning = new wxCheckBox(this, wxID_ANY, _("Continuous Scanning")wxGetTranslation(("Continuous Scanning")));
72 continuous_scanning->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnContinuousScanning, this);
73 continuous_scanning->SetValue(SConfig::GetInstance().m_WiimoteContinuousScanning);
74
75 auto wiimote_speaker = new wxCheckBox(this, wxID_ANY, _("Enable Speaker Data")wxGetTranslation(("Enable Speaker Data")));
76 wiimote_speaker->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnEnableSpeaker, this);
77 wiimote_speaker->SetValue(SConfig::GetInstance().m_WiimoteEnableSpeaker);
78
79 real_wiimotes_sizer->Add(continuous_scanning, 0, wxALIGN_CENTER_VERTICAL);
80 real_wiimotes_sizer->AddStretchSpacer(1);
81 real_wiimotes_sizer->Add(refresh_btn, 0, wxALL | wxALIGN_CENTER, 5);
82
83 real_wiimotes_group->Add(wiimote_speaker, 0);
84 real_wiimotes_group->Add(real_wiimotes_sizer, 0, wxEXPAND);
85
86 // "General Settings" controls
87 const wxString str[] = { _("Bottom")wxGetTranslation(("Bottom")), _("Top")wxGetTranslation(("Top")) };
88 wxChoice* const WiiSensBarPos = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, str);
89 wxSlider* const WiiSensBarSens = new wxSlider(this, wxID_ANY, 0, 0, 4, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTALwxHORIZONTAL);
90 wxSlider* const WiimoteSpkVolume = new wxSlider(this, wxID_ANY, 0, 0, 127);
91 wxCheckBox* const WiimoteMotor = new wxCheckBox(this, wxID_ANY, _("Wiimote Motor")wxGetTranslation(("Wiimote Motor")));
92 wxCheckBox* const WiimoteReconnectOnLoad = new wxCheckBox(this, wxID_ANY, _("Reconnect Wiimote on State Loading")wxGetTranslation(("Reconnect Wiimote on State Loading")));
93
94 wxStaticText* const WiiSensBarPosText = new wxStaticText(this, wxID_ANY, _("Sensor Bar Position:")wxGetTranslation(("Sensor Bar Position:")));
95 wxStaticText* const WiiSensBarSensText = new wxStaticText(this, wxID_ANY, _("IR Sensitivity:")wxGetTranslation(("IR Sensitivity:")));
96 wxStaticText* const WiiSensBarSensMinText = new wxStaticText(this, wxID_ANY, _("Min")wxGetTranslation(("Min")));
97 wxStaticText* const WiiSensBarSensMaxText = new wxStaticText(this, wxID_ANY, _("Max")wxGetTranslation(("Max")));
98 wxStaticText* const WiimoteSpkVolumeText = new wxStaticText(this, wxID_ANY, _("Speaker Volume:")wxGetTranslation(("Speaker Volume:")));
99 wxStaticText* const WiimoteSpkVolumeMinText = new wxStaticText(this, wxID_ANY, _("Min")wxGetTranslation(("Min")));
100 wxStaticText* const WiimoteSpkVolumeMaxText = new wxStaticText(this, wxID_ANY, _("Max")wxGetTranslation(("Max")));
101
102 // With some GTK themes, no minimum size will be applied - so do this manually here
103 WiiSensBarSens->SetMinSize(wxSize(100,-1));
104 WiimoteSpkVolume->SetMinSize(wxSize(100,-1));
105
106
107 // Disable some controls when emulation is running
108 if (Core::GetState() != Core::CORE_UNINITIALIZED)
109 {
110 WiiSensBarPos->Disable();
111 WiiSensBarSens->Disable();
112 WiimoteSpkVolume->Disable();
113 WiimoteMotor->Disable();
114 WiiSensBarPosText->Disable();
115 WiiSensBarSensText->Disable();
116 WiiSensBarSensMinText->Disable();
117 WiiSensBarSensMaxText->Disable();
118 WiimoteSpkVolumeText->Disable();
119 WiimoteSpkVolumeMinText->Disable();
120 WiimoteSpkVolumeMaxText->Disable();
121 }
122
123
124 // "General Settings" initialization
125 WiiSensBarPos->SetSelection(SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.BAR"));
126 WiiSensBarSens->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<u32>("BT.SENS"));
127 WiimoteSpkVolume->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.SPKV"));
128 WiimoteMotor->SetValue(SConfig::GetInstance().m_SYSCONF->GetData<bool>("BT.MOT"));
129 WiimoteReconnectOnLoad->SetValue(SConfig::GetInstance().m_WiimoteReconnectOnLoad);
130
131 WiiSensBarPos->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &WiimoteConfigDiag::OnSensorBarPos, this);
132 WiiSensBarSens->Bind(wxEVT_COMMAND_SLIDER_UPDATED, &WiimoteConfigDiag::OnSensorBarSensitivity, this);
133 WiimoteSpkVolume->Bind(wxEVT_COMMAND_SLIDER_UPDATED, &WiimoteConfigDiag::OnSpeakerVolume, this);
134 WiimoteMotor->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnMotor, this);
135 WiimoteReconnectOnLoad->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &WiimoteConfigDiag::OnReconnectOnLoad, this);
136
137
138 // "General Settings" layout
139 wxStaticBoxSizer* const general_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("General Settings")wxGetTranslation(("General Settings")));
140 wxFlexGridSizer* const choice_sizer = new wxFlexGridSizer(2, 5, 5);
141
142 wxBoxSizer* const sensbarsens_sizer = new wxBoxSizer(wxHORIZONTAL);
143 sensbarsens_sizer->Add(WiiSensBarSensMinText, 0, wxALIGN_CENTER_VERTICAL);
144 sensbarsens_sizer->Add(WiiSensBarSens);
145 sensbarsens_sizer->Add(WiiSensBarSensMaxText, 0, wxALIGN_CENTER_VERTICAL);
146
147 wxBoxSizer* const spkvol_sizer = new wxBoxSizer(wxHORIZONTAL);
148 spkvol_sizer->Add(WiimoteSpkVolumeMinText, 0, wxALIGN_CENTER_VERTICAL);
149 spkvol_sizer->Add(WiimoteSpkVolume);
150 spkvol_sizer->Add(WiimoteSpkVolumeMaxText, 0, wxALIGN_CENTER_VERTICAL);
151
152 choice_sizer->Add(WiiSensBarPosText, 0, wxALIGN_CENTER_VERTICAL);
153 choice_sizer->Add(WiiSensBarPos);
154 choice_sizer->Add(WiiSensBarSensText, 0, wxALIGN_CENTER_VERTICAL);
155 choice_sizer->Add(sensbarsens_sizer);
156 choice_sizer->Add(WiimoteSpkVolumeText, 0, wxALIGN_CENTER_VERTICAL);
157 choice_sizer->Add(spkvol_sizer);
158
159 wxGridSizer* const general_wiimote_sizer = new wxGridSizer(1, 5, 5);
160 general_wiimote_sizer->Add(WiimoteMotor);
161 general_wiimote_sizer->Add(WiimoteReconnectOnLoad);
162
163 general_sizer->Add(choice_sizer);
164 general_sizer->Add(general_wiimote_sizer);
165
166
167 // Dialog layout
168 main_sizer->Add(wiimote_group, 0, wxEXPAND | wxALL, 5);
169 main_sizer->Add(real_wiimotes_group, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
170 main_sizer->Add(general_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
171 main_sizer->Add(CreateButtonSizer(wxOK0x00000004 | wxCANCEL0x00000010), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
172
173 Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::Save, this, wxID_OK);
174 Bind(wxEVT_COMMAND_BUTTON_CLICKED, &WiimoteConfigDiag::Cancel, this, wxID_CANCEL);
175
176 SetSizerAndFit(main_sizer);
177 Center();
178}
179
180
181void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent& ev)
182{
183 InputConfigDialog* const m_emu_config_diag = new InputConfigDialog(this, m_plugin, _trans("Dolphin Emulated Wiimote Configuration")"Dolphin Emulated Wiimote Configuration", m_wiimote_index_from_conf_bt_id[ev.GetId()]);
184 m_emu_config_diag->ShowModal();
185 m_emu_config_diag->Destroy();
186}
187
188void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent&)
189{
190 WiimoteReal::Refresh();
191}
192
193void WiimoteConfigDiag::SelectSource(wxCommandEvent& event)
194{
195 // This needs to be changed now in order for refresh to work right.
196 // Revert if the dialog is canceled.
197 int index = m_wiimote_index_from_ctrl_id[event.GetId()];
198
199 WiimoteReal::ChangeWiimoteSource(index, event.GetInt());
200
201 if (g_wiimote_sources[index] != WIIMOTE_SRC_EMU && g_wiimote_sources[index] != WIIMOTE_SRC_HYBRID)
202 wiimote_configure_bt[index]->Disable();
203 else
204 wiimote_configure_bt[index]->Enable();
205}
206
207void WiimoteConfigDiag::RevertSource()
208{
209 for (int i = 0; i < 4; ++i)
210 g_wiimote_sources[i] = m_orig_wiimote_sources[i];
211}
212
213void WiimoteConfigDiag::Save(wxCommandEvent& event)
214{
215 std::string ini_filename = File::GetUserPath(D_CONFIG_IDX) + WIIMOTE_INI_NAME"WiimoteNew" ".ini";
216
217 IniFile inifile;
218 inifile.Load(ini_filename);
219
220 for (unsigned int i=0; i<MAX_WIIMOTES4; ++i)
221 {
222 std::string secname("Wiimote");
223 secname += (char)('1' + i);
224 IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
225
226 sec.Set("Source", (int)g_wiimote_sources[i]);
227 }
228
229 inifile.Save(ini_filename);
230
231 event.Skip();
232}
233
234void WiimoteConfigDiag::Cancel(wxCommandEvent& event)
235{
236 RevertSource();
237 event.Skip();
238}