Skip to content

Feat/project modernization#906

Merged
codeHusky merged 16 commits intosmartcmd:mainfrom
ModMaker101:feat/project-modernization
Mar 8, 2026
Merged

Feat/project modernization#906
codeHusky merged 16 commits intosmartcmd:mainfrom
ModMaker101:feat/project-modernization

Conversation

@ModMaker101
Copy link
Contributor

Description

Adds checks to prevent std::vector out of range access and null pointer dereferences that causes runtime assertions which caused a crash in my last PR.

Changes

Previous Behavior

Some rendering and UI code assumed pointers and vectors indices were always valid. In certain cases this cause the MSVC crash/assertion 'vector subscript out of range`.

Root Cause

  • Reverse loops using size_t could underflow when decrementing past 0.
  • Missing bounds checks when accessing vectors.
  • Missing null checks for objects.

New Behavior

The code now validates indices and pointers before use, preventing invalid vector access and null dereferences.

Fix Implementation

  • Replaced reverse loops using size_T with int to avoid unsinged underflow.
  • Added null checks before using objects.
  • Added bounds checks before accessing container slots.

AI Use Disclosure

No.

Related Issues/PR

@codeHusky Sorry about not testing it totally cross my mind while I was doing it, because I was just confident in my code which was a rookie mistake. But I tested this one and it was working just fine so if you could review this one.

@ModMaker101
Copy link
Contributor Author

2026-03-07.23-42-01.mp4

@codeHusky
Copy link
Collaborator

Tests okay for me (multiplayer, world gen, etc), merging!

@codeHusky codeHusky merged commit 28614b9 into smartcmd:main Mar 8, 2026
1 check passed
piebotc pushed a commit to piebotc/LegacyEvolved that referenced this pull request Mar 9, 2026
* Fixed boats falling and a TP glitch smartcmd#266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch smartcmd#266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides

* Add safety checks and fix a issue with vector going OOR
MrTheShy added a commit to MrTheShy/MinecraftConsoles that referenced this pull request Mar 9, 2026
…ain compile error

Merges 19 commits from smartcmd/MinecraftConsoles (upstream/main) into the
dedicated-server branch and resolves the resulting networking conflicts while
preserving all dedicated-server-specific behaviour.

---

Upstream commits included in this merge:

- Port over RCE Patches from LCEMP (smartcmd#1023)
  Hardened packet parsing across ByteArrayInputStream/OutputStream, Tag,
  Socket, Connection, and a dozen packet types; bounds-checked reads, length
  limits, and safe decompression paths to close known RCE vectors.

- Revert accidentally pushed "LCEMP RCE fixes" / LCEMP RCE fixes
  Intermediate clean-up of the above work.

- Reject duplicate UIDs on login and remove noisy gdraw debug log (smartcmd#1013)
  Incoming players whose UID is already active are now disconnected instead
  of force-kicking the existing player.  Removes a per-frame debug printf
  left in gdraw_SetViewSizeAndWorldScale.

- Always show version overlay, add more info
  Version string is now always visible at runtime.

- Fix split-screen UI wrong positioning on window resize (smartcmd#989)
- Reimplement boat gravity again (smartcmd#988)
- Use correctly sized icons on 720p (smartcmd#883)
- Revert workaround for loading HD textures (smartcmd#999)
- Fix crash when launching at 720p or lower resolutions (smartcmd#981)
- Modernize project codebase (smartcmd#906): NULL → nullptr, C-style cast → C++ cast,
  shared_ptr(new …) → make_shared, misc type fixes.
- Split screen, widescreen support, font rendering and UI scaling fixes (smartcmd#767)
- Flame not working with one-shot arrow (smartcmd#856)
- Fix focus sound playing repeatedly on mouse hover (smartcmd#890)
- Fix stale held item appearing when switching worlds (smartcmd#910)
- Fix F3 debug crash when throwing ender pearl long distance (smartcmd#934)
- Allow closing some menus with inventory/crafting keys (smartcmd#868)
- Fix second-person nametag pitch (smartcmd#963)

---

Conflict resolutions (4 files):

Minecraft.Client/Common/Network/GameNetworkManager.cpp
  Conflict 1 — variable declarations in StartNetworkGame:
    Kept HEAD.  The dedicated-server branch declares `dedicatedNoLocalHostPlayer`
    here and reads it from NetworkGameInitData.  Upstream had dropped that
    variable while modernising the NULL → nullptr style; keeping it is required
    for the dedicated-server startup path.
  Conflict 2 — primary-player connection block:
    Kept HEAD.  When `dedicatedNoLocalHostPlayer` is true the branch
    intentionally skips creating a local-host ClientConnection and goes
    straight to setting the game mode.  Upstream's refactor created a
    ClientConnection with a null socket even for the dedicated path and ran
    the full tick loop; that approach is incompatible with headless operation.

Minecraft.Client/PendingConnection.cpp
  Kept HEAD.  The branch wraps the duplicate-XUID rejection path with a
  #if MINECRAFT_SERVER_BUILD guard that calls
  ServerLogManager::OnRejectedPlayerLogin.  Upstream's version removed that
  call and rewrote only the comment.  Preserving the guard keeps the
  server-build audit log intact.

Minecraft.Client/ServerConnection.cpp
  Kept HEAD comment.  Both sides changed only a single-line comment above
  the playerSnapshot vector.  HEAD's comment ("Disconnect through
  PlayerConnection so clients receive a proper DisconnectPacket before socket
  close") describes the functional intent; it was kept as the more meaningful
  description for this branch.

Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp
  Conflicts 1 & 2 — shutdown thread teardown:
    Hybrid: adopted upstream's nullptr style (consistent with the rest of the
    file after the modernisation PR) while keeping HEAD's more precise comment
    ("Ensure all host-side receive threads have exited before destroying locks").
  Conflict 3 — AcceptThreadProc accept() call:
    Kept HEAD.  HEAD passes sockaddr_in remoteAddress to accept() so that
    TryGetNumericRemoteIp can extract the client IP for connection logging
    and the IP-ban check (ServerRuntime::Access::IsIpBanned).  Upstream had
    simplified the call to accept(…, nullptr, nullptr), which would have
    silently broken IP-based access control in the server build.

---

fix: declare extern ConsoleUIController ui in ServerMain.cpp

Windows64_UIController.h (included by ServerMain.cpp) defines the class but
does not forward-declare the global `ui` instance.  The `extern ConsoleUIController ui`
declaration lives only in Common/UI/UI.h, which is not in ServerMain.cpp's
include chain.  The object is defined in Windows64_UIController.cpp, which IS
compiled as part of Minecraft.Server.vcxproj, so the linker already sees it;
the missing declaration caused a C2065 compile error only in the server
translation unit.  Added the extern declaration alongside the other extern
globals at the top of ServerMain.cpp.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants