Skip to content

Commit cc92ca3

Browse files
ZXShadyChrisThrasher
authored andcommitted
Pass by reference if it is never null
sfEvent was not checked for null and was assumed to be non null in convertEvent so I made it a reference to reflect that
1 parent 556ca51 commit cc92ca3

File tree

4 files changed

+70
-70
lines changed

4 files changed

+70
-70
lines changed

src/CSFML/Graphics/RenderWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, sfEvent* event)
145145
{
146146
assert(renderWindow);
147147
assert(event);
148-
return convertEvent(renderWindow->pollEvent(), event);
148+
return convertEvent(renderWindow->pollEvent(), *event);
149149
}
150150

151151

@@ -154,7 +154,7 @@ bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfTime timeout, sfEv
154154
{
155155
assert(renderWindow);
156156
assert(event);
157-
return convertEvent(renderWindow->waitEvent(sf::microseconds(timeout.microseconds)), event);
157+
return convertEvent(renderWindow->waitEvent(sf::microseconds(timeout.microseconds)), *event);
158158
}
159159

160160

src/CSFML/Window/ConvertEvent.hpp

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -39,142 +39,142 @@
3939
////////////////////////////////////////////////////////////
4040
// Convert sf::Event to sfEvent
4141
////////////////////////////////////////////////////////////
42-
[[nodiscard]] inline bool convertEvent(const std::optional<sf::Event>& sfmlEvent, sfEvent* event)
42+
[[nodiscard]] inline bool convertEvent(const std::optional<sf::Event>& sfmlEvent, sfEvent& event)
4343
{
4444
if (!sfmlEvent)
4545
return false;
4646

4747
if (sfmlEvent->is<sf::Event::Closed>())
4848
{
49-
event->type = sfEvtClosed;
49+
event.type = sfEvtClosed;
5050
}
5151
else if (const auto* resized = sfmlEvent->getIf<sf::Event::Resized>())
5252
{
53-
event->type = sfEvtResized;
54-
event->size.size = convertVector2(resized->size);
53+
event.type = sfEvtResized;
54+
event.size.size = convertVector2(resized->size);
5555
}
5656
else if (sfmlEvent->is<sf::Event::FocusLost>())
5757
{
58-
event->type = sfEvtFocusLost;
58+
event.type = sfEvtFocusLost;
5959
}
6060
else if (sfmlEvent->is<sf::Event::FocusGained>())
6161
{
62-
event->type = sfEvtFocusGained;
62+
event.type = sfEvtFocusGained;
6363
}
6464
else if (const auto* textEntered = sfmlEvent->getIf<sf::Event::TextEntered>())
6565
{
66-
event->type = sfEvtTextEntered;
67-
event->text.unicode = textEntered->unicode;
66+
event.type = sfEvtTextEntered;
67+
event.text.unicode = textEntered->unicode;
6868
}
6969
else if (const auto* keyReleased = sfmlEvent->getIf<sf::Event::KeyReleased>())
7070
{
71-
event->type = sfEvtKeyReleased;
72-
event->key.code = static_cast<sfKeyCode>(keyReleased->code);
73-
event->key.scancode = static_cast<sfScancode>(keyReleased->scancode);
74-
event->key.alt = keyReleased->alt;
75-
event->key.control = keyReleased->control;
76-
event->key.shift = keyReleased->shift;
77-
event->key.system = keyReleased->system;
71+
event.type = sfEvtKeyReleased;
72+
event.key.code = static_cast<sfKeyCode>(keyReleased->code);
73+
event.key.scancode = static_cast<sfScancode>(keyReleased->scancode);
74+
event.key.alt = keyReleased->alt;
75+
event.key.control = keyReleased->control;
76+
event.key.shift = keyReleased->shift;
77+
event.key.system = keyReleased->system;
7878
}
7979
else if (const auto* keyPressed = sfmlEvent->getIf<sf::Event::KeyPressed>())
8080
{
81-
event->type = sfEvtKeyPressed;
82-
event->key.code = static_cast<sfKeyCode>(keyPressed->code);
83-
event->key.scancode = static_cast<sfScancode>(keyPressed->scancode);
84-
event->key.alt = keyPressed->alt;
85-
event->key.control = keyPressed->control;
86-
event->key.shift = keyPressed->shift;
87-
event->key.system = keyPressed->system;
81+
event.type = sfEvtKeyPressed;
82+
event.key.code = static_cast<sfKeyCode>(keyPressed->code);
83+
event.key.scancode = static_cast<sfScancode>(keyPressed->scancode);
84+
event.key.alt = keyPressed->alt;
85+
event.key.control = keyPressed->control;
86+
event.key.shift = keyPressed->shift;
87+
event.key.system = keyPressed->system;
8888
}
8989
else if (const auto* mouseWheelScrolled = sfmlEvent->getIf<sf::Event::MouseWheelScrolled>())
9090
{
91-
event->type = sfEvtMouseWheelScrolled;
92-
event->mouseWheelScroll.wheel = static_cast<sfMouseWheel>(mouseWheelScrolled->wheel);
93-
event->mouseWheelScroll.delta = mouseWheelScrolled->delta;
94-
event->mouseWheelScroll.position = convertVector2(mouseWheelScrolled->position);
91+
event.type = sfEvtMouseWheelScrolled;
92+
event.mouseWheelScroll.wheel = static_cast<sfMouseWheel>(mouseWheelScrolled->wheel);
93+
event.mouseWheelScroll.delta = mouseWheelScrolled->delta;
94+
event.mouseWheelScroll.position = convertVector2(mouseWheelScrolled->position);
9595
}
9696
else if (const auto* mouseButtonPressed = sfmlEvent->getIf<sf::Event::MouseButtonPressed>())
9797
{
98-
event->type = sfEvtMouseButtonPressed;
99-
event->mouseButton.button = static_cast<sfMouseButton>(mouseButtonPressed->button);
100-
event->mouseButton.position = convertVector2(mouseButtonPressed->position);
98+
event.type = sfEvtMouseButtonPressed;
99+
event.mouseButton.button = static_cast<sfMouseButton>(mouseButtonPressed->button);
100+
event.mouseButton.position = convertVector2(mouseButtonPressed->position);
101101
}
102102
else if (const auto* mouseButtonReleased = sfmlEvent->getIf<sf::Event::MouseButtonReleased>())
103103
{
104-
event->type = sfEvtMouseButtonReleased;
105-
event->mouseButton.button = static_cast<sfMouseButton>(mouseButtonReleased->button);
106-
event->mouseButton.position = convertVector2(mouseButtonReleased->position);
104+
event.type = sfEvtMouseButtonReleased;
105+
event.mouseButton.button = static_cast<sfMouseButton>(mouseButtonReleased->button);
106+
event.mouseButton.position = convertVector2(mouseButtonReleased->position);
107107
}
108108
else if (const auto* mouseMoved = sfmlEvent->getIf<sf::Event::MouseMoved>())
109109
{
110-
event->type = sfEvtMouseMoved;
111-
event->mouseMove.position = convertVector2(mouseMoved->position);
110+
event.type = sfEvtMouseMoved;
111+
event.mouseMove.position = convertVector2(mouseMoved->position);
112112
}
113113
else if (const auto* mouseMovedRaw = sfmlEvent->getIf<sf::Event::MouseMovedRaw>())
114114
{
115-
event->type = sfEvtMouseMovedRaw;
116-
event->mouseMoveRaw.delta = convertVector2(mouseMovedRaw->delta);
115+
event.type = sfEvtMouseMovedRaw;
116+
event.mouseMoveRaw.delta = convertVector2(mouseMovedRaw->delta);
117117
}
118118
else if (sfmlEvent->is<sf::Event::MouseEntered>())
119119
{
120-
event->type = sfEvtMouseEntered;
120+
event.type = sfEvtMouseEntered;
121121
}
122122
else if (sfmlEvent->is<sf::Event::MouseLeft>())
123123
{
124-
event->type = sfEvtMouseLeft;
124+
event.type = sfEvtMouseLeft;
125125
}
126126
else if (const auto* joystickButtonPressed = sfmlEvent->getIf<sf::Event::JoystickButtonPressed>())
127127
{
128-
event->type = sfEvtJoystickButtonPressed;
129-
event->joystickButton.joystickId = joystickButtonPressed->joystickId;
130-
event->joystickButton.button = joystickButtonPressed->button;
128+
event.type = sfEvtJoystickButtonPressed;
129+
event.joystickButton.joystickId = joystickButtonPressed->joystickId;
130+
event.joystickButton.button = joystickButtonPressed->button;
131131
}
132132
else if (const auto* joystickButtonReleased = sfmlEvent->getIf<sf::Event::JoystickButtonReleased>())
133133
{
134-
event->type = sfEvtJoystickButtonReleased;
135-
event->joystickButton.joystickId = joystickButtonReleased->joystickId;
136-
event->joystickButton.button = joystickButtonReleased->button;
134+
event.type = sfEvtJoystickButtonReleased;
135+
event.joystickButton.joystickId = joystickButtonReleased->joystickId;
136+
event.joystickButton.button = joystickButtonReleased->button;
137137
}
138138
else if (const auto* joystickMoved = sfmlEvent->getIf<sf::Event::JoystickMoved>())
139139
{
140-
event->type = sfEvtJoystickMoved;
141-
event->joystickMove.joystickId = joystickMoved->joystickId;
142-
event->joystickMove.axis = static_cast<sfJoystickAxis>(joystickMoved->axis);
143-
event->joystickMove.position = joystickMoved->position;
140+
event.type = sfEvtJoystickMoved;
141+
event.joystickMove.joystickId = joystickMoved->joystickId;
142+
event.joystickMove.axis = static_cast<sfJoystickAxis>(joystickMoved->axis);
143+
event.joystickMove.position = joystickMoved->position;
144144
}
145145
else if (const auto* joystickConnected = sfmlEvent->getIf<sf::Event::JoystickConnected>())
146146
{
147-
event->type = sfEvtJoystickConnected;
148-
event->joystickConnect.joystickId = joystickConnected->joystickId;
147+
event.type = sfEvtJoystickConnected;
148+
event.joystickConnect.joystickId = joystickConnected->joystickId;
149149
}
150150
else if (const auto* joystickDisconnected = sfmlEvent->getIf<sf::Event::JoystickDisconnected>())
151151
{
152-
event->type = sfEvtJoystickDisconnected;
153-
event->joystickConnect.joystickId = joystickDisconnected->joystickId;
152+
event.type = sfEvtJoystickDisconnected;
153+
event.joystickConnect.joystickId = joystickDisconnected->joystickId;
154154
}
155155
else if (const auto* touchBegan = sfmlEvent->getIf<sf::Event::TouchBegan>())
156156
{
157-
event->type = sfEvtTouchBegan;
158-
event->touch.finger = touchBegan->finger;
159-
event->touch.position = convertVector2(touchBegan->position);
157+
event.type = sfEvtTouchBegan;
158+
event.touch.finger = touchBegan->finger;
159+
event.touch.position = convertVector2(touchBegan->position);
160160
}
161161
else if (const auto* touchMoved = sfmlEvent->getIf<sf::Event::TouchMoved>())
162162
{
163-
event->type = sfEvtTouchMoved;
164-
event->touch.finger = touchMoved->finger;
165-
event->touch.position = convertVector2(touchMoved->position);
163+
event.type = sfEvtTouchMoved;
164+
event.touch.finger = touchMoved->finger;
165+
event.touch.position = convertVector2(touchMoved->position);
166166
}
167167
else if (const auto* touchEnded = sfmlEvent->getIf<sf::Event::TouchEnded>())
168168
{
169-
event->type = sfEvtTouchEnded;
170-
event->touch.finger = touchEnded->finger;
171-
event->touch.position = convertVector2(touchEnded->position);
169+
event.type = sfEvtTouchEnded;
170+
event.touch.finger = touchEnded->finger;
171+
event.touch.position = convertVector2(touchEnded->position);
172172
}
173173
else if (const auto* sensorChanged = sfmlEvent->getIf<sf::Event::SensorChanged>())
174174
{
175-
event->type = sfEvtSensorChanged;
176-
event->sensor.sensorType = static_cast<sfSensorType>(sensorChanged->type);
177-
event->sensor.value = convertVector3(sensorChanged->value);
175+
event.type = sfEvtSensorChanged;
176+
event.sensor.sensorType = static_cast<sfSensorType>(sensorChanged->type);
177+
event.sensor.value = convertVector3(sensorChanged->value);
178178
}
179179

180180
return true;

src/CSFML/Window/Window.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool sfWindow_pollEvent(sfWindow* window, sfEvent* event)
114114
{
115115
assert(window);
116116
assert(event);
117-
return convertEvent(window->pollEvent(), event);
117+
return convertEvent(window->pollEvent(), *event);
118118
}
119119

120120

@@ -123,7 +123,7 @@ bool sfWindow_waitEvent(sfWindow* window, sfTime timeout, sfEvent* event)
123123
{
124124
assert(window);
125125
assert(event);
126-
return convertEvent(window->waitEvent(sf::microseconds(timeout.microseconds)), event);
126+
return convertEvent(window->waitEvent(sf::microseconds(timeout.microseconds)), *event);
127127
}
128128

129129

src/CSFML/Window/WindowBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bool sfWindowBase_pollEvent(sfWindowBase* windowBase, sfEvent* event)
9696
{
9797
assert(windowBase);
9898
assert(event);
99-
return convertEvent(windowBase->pollEvent(), event);
99+
return convertEvent(windowBase->pollEvent(), *event);
100100
}
101101

102102

@@ -105,7 +105,7 @@ bool sfWindowBase_waitEvent(sfWindowBase* windowBase, sfTime timeout, sfEvent* e
105105
{
106106
assert(windowBase);
107107
assert(event);
108-
return convertEvent(windowBase->waitEvent(sf::microseconds(timeout.microseconds)), event);
108+
return convertEvent(windowBase->waitEvent(sf::microseconds(timeout.microseconds)), *event);
109109
}
110110

111111

0 commit comments

Comments
 (0)