Check for nullptr explicitly in operct2-ui (#15460)

This commit is contained in:
Hielke Morsink 2021-09-25 08:45:06 +02:00 committed by GitHub
parent 53c22c9b4b
commit a8b84989eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 49 deletions

View File

@ -748,7 +748,7 @@ static void InputScrollPartUpdateHThumb(rct_window* w, rct_widgetindex widgetInd
{
rct_widget* widget = &w->widgets[widgetIndex];
if (window_find_by_number(w->classification, w->number))
if (window_find_by_number(w->classification, w->number) != nullptr)
{
int32_t newLeft;
newLeft = w->scrolls[scroll_id].h_right;
@ -787,7 +787,7 @@ static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetInd
assert(w != nullptr);
rct_widget* widget = &w->widgets[widgetIndex];
if (window_find_by_number(w->classification, w->number))
if (window_find_by_number(w->classification, w->number) != nullptr)
{
int32_t newTop;
newTop = w->scrolls[scroll_id].v_bottom;
@ -824,7 +824,7 @@ static void InputScrollPartUpdateVThumb(rct_window* w, rct_widgetindex widgetInd
static void InputScrollPartUpdateHLeft(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id)
{
assert(w != nullptr);
if (window_find_by_number(w->classification, w->number))
if (window_find_by_number(w->classification, w->number) != nullptr)
{
w->scrolls[scroll_id].flags |= HSCROLLBAR_LEFT_PRESSED;
if (w->scrolls[scroll_id].h_left >= 3)
@ -842,7 +842,7 @@ static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetInd
{
assert(w != nullptr);
rct_widget* widget = &w->widgets[widgetIndex];
if (window_find_by_number(w->classification, w->number))
if (window_find_by_number(w->classification, w->number) != nullptr)
{
w->scrolls[scroll_id].flags |= HSCROLLBAR_RIGHT_PRESSED;
w->scrolls[scroll_id].h_left += 3;
@ -867,7 +867,7 @@ static void InputScrollPartUpdateHRight(rct_window* w, rct_widgetindex widgetInd
static void InputScrollPartUpdateVTop(rct_window* w, rct_widgetindex widgetIndex, int32_t scroll_id)
{
assert(w != nullptr);
if (window_find_by_number(w->classification, w->number))
if (window_find_by_number(w->classification, w->number) != nullptr)
{
w->scrolls[scroll_id].flags |= VSCROLLBAR_UP_PRESSED;
if (w->scrolls[scroll_id].v_top >= 3)
@ -885,7 +885,7 @@ static void InputScrollPartUpdateVBottom(rct_window* w, rct_widgetindex widgetIn
{
assert(w != nullptr);
rct_widget* widget = &w->widgets[widgetIndex];
if (window_find_by_number(w->classification, w->number))
if (window_find_by_number(w->classification, w->number) != nullptr)
{
w->scrolls[scroll_id].flags |= VSCROLLBAR_DOWN_PRESSED;
w->scrolls[scroll_id].v_top += 3;
@ -1170,7 +1170,7 @@ void ProcessMouseTool(const ScreenCoordsXY& screenCoords)
{
rct_window* w = window_find_by_number(gCurrentToolWidget.window_classification, gCurrentToolWidget.window_number);
if (!w)
if (w == nullptr)
tool_cancel();
else
window_event_tool_update_call(w, gCurrentToolWidget.widget_index, screenCoords);
@ -1200,7 +1200,8 @@ void InputStateWidgetPressed(
switch (state)
{
case MouseState::Released:
if (!w || cursor_w_class != w->classification || cursor_w_number != w->number || widgetIndex != cursor_widgetIndex)
if (w == nullptr || cursor_w_class != w->classification || cursor_w_number != w->number
|| widgetIndex != cursor_widgetIndex)
break;
if (w->disabled_widgets & (1ULL << widgetIndex))
@ -1237,7 +1238,7 @@ void InputStateWidgetPressed(
case MouseState::RightPress:
if (_inputState == InputState::DropdownActive)
{
if (w)
if (w != nullptr)
{
auto wClass = w->classification;
auto wNumber = w->number;
@ -1317,10 +1318,10 @@ void InputStateWidgetPressed(
gTooltipTimeout = 0;
gTooltipWidget.widget_index = cursor_widgetIndex;
if (!w)
if (w == nullptr)
break;
if (!widget)
if (widget == nullptr)
break;
{

View File

@ -175,7 +175,7 @@ public:
Close();
break;
case WIDX_OPEN_URL:
if (_newVersionInfo)
if (_newVersionInfo != nullptr)
{
GetContext()->GetUiContext()->OpenURL(_newVersionInfo->url);
}

View File

@ -595,7 +595,7 @@ void window_guest_overview_mouse_up(rct_window* w, rct_widgetindex widgetIndex)
if (result->Error != GameActions::Status::Ok)
return;
rct_window* wind = window_find_by_number(WC_PEEP, peepnum);
if (wind)
if (wind != nullptr)
{
tool_set(wind, WC_PEEP__WIDX_PICKUP, Tool::Picker);
}
@ -678,7 +678,7 @@ void window_guest_set_page(rct_window* w, int32_t page)
tool_cancel();
}
int32_t listen = 0;
if (page == WINDOW_GUEST_OVERVIEW && w->page == WINDOW_GUEST_OVERVIEW && w->viewport)
if (page == WINDOW_GUEST_OVERVIEW && w->page == WINDOW_GUEST_OVERVIEW && w->viewport != nullptr)
{
if (!(w->viewport->flags & VIEWPORT_FLAG_SOUND_ON))
listen = 1;
@ -703,7 +703,7 @@ void window_guest_set_page(rct_window* w, int32_t page)
WindowInitScrollWidgets(w);
w->Invalidate();
if (listen && w->viewport)
if (listen && w->viewport != nullptr)
w->viewport->flags |= VIEWPORT_FLAG_SOUND_ON;
}
@ -986,7 +986,7 @@ void window_guest_overview_paint(rct_window* w, rct_drawpixelinfo* dpi)
window_guest_debug_tab_paint(w, dpi);
// Draw the viewport no sound sprite
if (w->viewport)
if (w->viewport != nullptr)
{
window_draw_viewport(dpi, w);
rct_viewport* viewport = w->viewport;

View File

@ -2011,7 +2011,7 @@ static void window_options_advanced_mouseup(rct_window* w, rct_widgetindex widge
case WIDX_PATH_TO_RCT1_BUTTON:
{
utf8string rct1path = platform_open_directory_browser(language_get_string(STR_PATH_TO_RCT1_BROWSER));
if (rct1path)
if (rct1path != nullptr)
{
// Check if this directory actually contains RCT1
if (Csg1datPresentAtLocation(rct1path))

View File

@ -1485,7 +1485,7 @@ static void window_ride_set_page(rct_window* w, int32_t page)
if (page == WINDOW_RIDE_PAGE_VEHICLE)
{
auto constructionWindow = window_find_by_class(WC_RIDE_CONSTRUCTION);
if (constructionWindow && constructionWindow->number == w->number)
if (constructionWindow != nullptr && constructionWindow->number == w->number)
{
window_close_by_class(WC_RIDE_CONSTRUCTION);
// Closing the construction window sets the tab to the first page, which we don't want here,
@ -1595,7 +1595,7 @@ static void window_ride_init_viewport(rct_window* w)
{
uint16_t vehId = ride->vehicles[viewSelectionIndex];
rct_ride_entry* ride_entry = ride->GetRideEntry();
if (ride_entry && ride_entry->tab_vehicle != 0)
if (ride_entry != nullptr && ride_entry->tab_vehicle != 0)
{
Vehicle* vehicle = GetEntity<Vehicle>(vehId);
if (vehicle == nullptr)
@ -1654,7 +1654,7 @@ static void window_ride_init_viewport(rct_window* w)
w->focus = focus;
// rct2: 0x006aec9c only used here so brought it into the function
if (!w->viewport && !ride->overall_view.IsNull())
if (w->viewport == nullptr && !ride->overall_view.IsNull())
{
rct_widget* view_widget = &w->widgets[WIDX_VIEWPORT];
@ -1667,7 +1667,7 @@ static void window_ride_init_viewport(rct_window* w)
w->flags |= WF_NO_SCROLLING;
w->Invalidate();
}
if (w->viewport)
if (w->viewport != nullptr)
{
w->viewport->flags = viewport_flags;
w->Invalidate();
@ -5225,8 +5225,7 @@ static void cancel_scenery_selection()
OpenRCT2::Audio::Resume();
rct_window* main_w = window_get_main();
if (main_w)
if (main_w != nullptr)
{
main_w->viewport->flags &= ~(VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE);
}
@ -5258,8 +5257,7 @@ static void setup_scenery_selection(rct_window* w)
OpenRCT2::Audio::StopAll();
rct_window* w_main = window_get_main();
if (w_main)
if (w_main != nullptr)
{
w_main->viewport->flags |= (VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE);
}

View File

@ -2139,7 +2139,7 @@ static std::optional<CoordsXY> ride_get_place_position_from_screen_position(Scre
_trackPlaceShiftZ = _trackPlaceShiftStart.y - screenCoords.y + 4;
// Scale delta by zoom to match mouse position.
auto* mainWnd = window_get_main();
if (mainWnd && mainWnd->viewport)
if (mainWnd != nullptr && mainWnd->viewport != nullptr)
{
_trackPlaceShiftZ = _trackPlaceShiftZ * mainWnd->viewport->zoom;
}
@ -3566,17 +3566,18 @@ void ride_construction_toolupdate_construct(const ScreenCoordsXY& screenCoords)
{
pathsByDir[i] = map_get_footpath_element({ *mapCoords + CoordsDirectionDelta[i], z });
if (pathsByDir[i] && (pathsByDir[i])->AsPath()->IsSloped() && (pathsByDir[i])->AsPath()->GetSlopeDirection() != i)
if (pathsByDir[i] != nullptr && (pathsByDir[i])->AsPath()->IsSloped()
&& (pathsByDir[i])->AsPath()->GetSlopeDirection() != i)
{
pathsByDir[i] = nullptr;
}
// Sloped path on the level below
if (!pathsByDir[i])
if (pathsByDir[i] == nullptr)
{
pathsByDir[i] = map_get_footpath_element({ *mapCoords + CoordsDirectionDelta[i], z - PATH_HEIGHT_STEP });
if (pathsByDir[i]
if (pathsByDir[i] != nullptr
&& (!(pathsByDir[i])->AsPath()->IsSloped()
|| (pathsByDir[i])->AsPath()->GetSlopeDirection() != direction_reverse(i)))
{
@ -3584,12 +3585,12 @@ void ride_construction_toolupdate_construct(const ScreenCoordsXY& screenCoords)
}
}
if (pathsByDir[i] && (pathsByDir[i])->AsPath()->IsQueue())
if (pathsByDir[i] != nullptr && (pathsByDir[i])->AsPath()->IsQueue())
{
pathsByDir[i] = nullptr;
}
if (pathsByDir[i] && i == _currentTrackPieceDirection)
if (pathsByDir[i] != nullptr && i == _currentTrackPieceDirection)
{
keepOrientation = true;
break;
@ -3600,7 +3601,7 @@ void ride_construction_toolupdate_construct(const ScreenCoordsXY& screenCoords)
{
for (int8_t i = 0; i < 4; i++)
{
if (pathsByDir[i])
if (pathsByDir[i] != nullptr)
{
_currentTrackPieceDirection = i;

View File

@ -121,7 +121,7 @@ rct_window* window_save_prompt_open()
// Check if window is already open
window = window_bring_to_front_by_class(WC_SAVE_PROMPT);
if (window)
if (window != nullptr)
{
window_close(window);
}

View File

@ -357,7 +357,7 @@ void window_staff_set_page(rct_window* w, int32_t page)
}
int32_t listen = 0;
if (page == WINDOW_STAFF_OVERVIEW && w->page == WINDOW_STAFF_OVERVIEW && w->viewport)
if (page == WINDOW_STAFF_OVERVIEW && w->page == WINDOW_STAFF_OVERVIEW && w->viewport != nullptr)
{
if (!(w->viewport->flags & VIEWPORT_FLAG_SOUND_ON))
listen = 1;
@ -383,7 +383,7 @@ void window_staff_set_page(rct_window* w, int32_t page)
WindowInitScrollWidgets(w);
w->Invalidate();
if (listen && w->viewport)
if (listen && w->viewport != nullptr)
w->viewport->flags |= VIEWPORT_FLAG_SOUND_ON;
}
@ -419,7 +419,7 @@ void window_staff_overview_mouseup(rct_window* w, rct_widgetindex widgetIndex)
if (result->Error != GameActions::Status::Ok)
return;
rct_window* wind = window_find_by_number(WC_PEEP, peepnum);
if (wind)
if (wind != nullptr)
{
tool_set(wind, WC_STAFF__WIDX_PICKUP, Tool::Picker);
}
@ -482,8 +482,7 @@ void window_staff_overview_resize(rct_window* w)
}
rct_viewport* viewport = w->viewport;
if (viewport)
if (viewport != nullptr)
{
int32_t new_width = w->width - 30;
int32_t new_height = w->height - 62;
@ -954,7 +953,7 @@ void window_staff_overview_paint(rct_window* w, rct_drawpixelinfo* dpi)
window_staff_stats_tab_paint(w, dpi);
// Draw the viewport no sound sprite
if (w->viewport)
if (w->viewport != nullptr)
{
window_draw_viewport(dpi, w);
rct_viewport* viewport = w->viewport;
@ -1361,7 +1360,7 @@ void window_staff_viewport_init(rct_window* w)
uint16_t viewport_flags;
if (w->viewport)
if (w->viewport != nullptr)
{
if (focus == w->focus)
return;
@ -1382,7 +1381,7 @@ void window_staff_viewport_init(rct_window* w)
if (peep->State != PeepState::Picked)
{
if (!(w->viewport))
if (w->viewport == nullptr)
{
rct_widget* view_widget = &w->widgets[WIDX_VIEWPORT];
@ -1396,7 +1395,7 @@ void window_staff_viewport_init(rct_window* w)
}
}
if (w->viewport)
if (w->viewport != nullptr)
w->viewport->flags = viewport_flags;
w->Invalidate();
}

View File

@ -1215,7 +1215,7 @@ static void sub_6E1F34_update_screen_coords_and_buttons_pressed(bool canRaiseIte
gSceneryShiftPressZOffset = (gSceneryShiftPressY - screenPos.y + 4);
// Scale delta by zoom to match mouse position.
auto* mainWnd = window_get_main();
if (mainWnd && mainWnd->viewport)
if (mainWnd != nullptr && mainWnd->viewport != nullptr)
{
gSceneryShiftPressZOffset = gSceneryShiftPressZOffset * mainWnd->viewport->zoom;
}
@ -3058,7 +3058,7 @@ static money64 selection_lower_land(uint8_t flags)
static void window_top_toolbar_land_tool_drag(const ScreenCoordsXY& screenPos)
{
rct_window* window = window_find_from_point(screenPos);
if (!window)
if (window == nullptr)
return;
rct_widgetindex widget_index = window_find_widget_from_point(window, screenPos);
if (widget_index == -1)
@ -3067,7 +3067,7 @@ static void window_top_toolbar_land_tool_drag(const ScreenCoordsXY& screenPos)
if (widget->type != WindowWidgetType::Viewport)
return;
rct_viewport* viewport = window->viewport;
if (!viewport)
if (viewport == nullptr)
return;
int16_t tile_height = -16 / viewport->zoom;
@ -3110,7 +3110,7 @@ static void window_top_toolbar_water_tool_drag(const ScreenCoordsXY& screenPos)
if (widget->type != WindowWidgetType::Viewport)
return;
rct_viewport* viewport = window->viewport;
if (!viewport)
if (viewport == nullptr)
return;
int16_t dx = -16 / viewport->zoom;
@ -3555,7 +3555,7 @@ static void top_toolbar_init_network_menu(rct_window* w, rct_widget* widget)
static void top_toolbar_debug_menu_dropdown(int16_t dropdownIndex)
{
rct_window* w = window_get_main();
if (w)
if (w != nullptr)
{
switch (dropdownIndex)
{
@ -3582,7 +3582,7 @@ static void top_toolbar_debug_menu_dropdown(int16_t dropdownIndex)
static void top_toolbar_network_menu_dropdown(int16_t dropdownIndex)
{
rct_window* w = window_get_main();
if (w)
if (w != nullptr)
{
switch (dropdownIndex)
{
@ -3678,7 +3678,7 @@ static void top_toolbar_init_view_menu(rct_window* w, rct_widget* widget)
static void top_toolbar_view_menu_dropdown(int16_t dropdownIndex)
{
rct_window* w = window_get_main();
if (w)
if (w != nullptr)
{
switch (dropdownIndex)
{