Add safety checks and fix a issue with vector going OOR

This commit is contained in:
Chase Cooper 2026-03-07 23:27:09 -05:00
parent 98c5325b90
commit 699d84b70c
15 changed files with 112 additions and 8 deletions

View file

@ -102,7 +102,7 @@ void UILayer::render(S32 width, S32 height, C4JRender::eViewportType viewport)
bool UILayer::IsSceneInStack(EUIScene scene)
{
bool inStack = false;
for(size_t i = (int)m_sceneStack.size() - 1;i >= 0; --i)
for(int i = static_cast<int>(m_sceneStack.size()) - 1; i >= 0; --i)
{
if(m_sceneStack[i]->getSceneType() == scene)
{
@ -118,7 +118,7 @@ bool UILayer::HasFocus(int iPad)
bool hasFocus = false;
if(m_hasFocus)
{
for(size_t i = (int)m_sceneStack.size() - 1;i >= 0; --i)
for(int i = (int)m_sceneStack.size() - 1; i >= 0; --i)
{
if(m_sceneStack[i]->stealsFocus() )
{
@ -146,7 +146,7 @@ bool UILayer::hidesLowerScenes()
}
if(!hidesScenes && !m_sceneStack.empty())
{
for(size_t i = (int)m_sceneStack.size() - 1;i >= 0; --i)
for(int i = static_cast<int>(m_sceneStack.size()) - 1; i >= 0; --i)
{
if(m_sceneStack[i]->hidesLowerScenes())
{

View file

@ -244,6 +244,11 @@ void EntityRenderDispatcher::prepare(Level *level, Textures *textures, Font *fon
void EntityRenderDispatcher::render(shared_ptr<Entity> entity, float a)
{
if (entity == nullptr)
{
return;
}
double x = entity->xOld + (entity->x - entity->xOld) * a;
double y = entity->yOld + (entity->y - entity->yOld) * a;
double z = entity->zOld + (entity->z - entity->zOld) * a;

View file

@ -1133,6 +1133,11 @@ int GameRenderer::getLightTexture(int iPad, Level *level)
void GameRenderer::render(float a, bool bFirst)
{
if (mc->player == nullptr)
{
return;
}
if( _updateLightTexture && bFirst) updateLightTexture(a);
if (Display::isActive())
{

View file

@ -63,6 +63,12 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
// 4J Stu - I have copied this code for XUI_BaseScene. If/when it gets changed it should be broken out
// 4J - altered to force full screen mode to 3X scaling, and any split screen modes to 2X scaling. This is so that the further scaling by 0.5 that
// happens in split screen modes results in a final scaling of 1 rather than 1.5.
if (minecraft->player == nullptr)
{
return;
}
int splitYOffset;// = 20; // This offset is applied when doing the 2X scaling above to move the gui out of the way of the tool tips
int guiScale;// = ( minecraft->player->m_iScreenSection == C4JRender::VIEWPORT_TYPE_FULLSCREEN ? 3 : 2 );
int iPad=minecraft->player->GetXboxPad();
@ -845,7 +851,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse)
#ifndef _FINAL_BUILD
MemSect(31);
if (minecraft->options->renderDebug)
if (minecraft->options->renderDebug && minecraft->player != nullptr && minecraft->level != nullptr)
{
const int debugLeft = 1;
const int debugTop = 1;

View file

@ -373,6 +373,11 @@ void ItemInHandRenderer::render(float a)
float h = oHeight + (height - oHeight) * a;
shared_ptr<Player> player = minecraft->player;
if (player == nullptr)
{
return;
}
// 4J - added so we can adjust the position of the hands for horizontal & vertical split screens
float fudgeX = 0.0f;
float fudgeY = 0.0f;

View file

@ -507,6 +507,11 @@ void LevelRenderer::allChanged(int playerIndex)
void LevelRenderer::renderEntities(Vec3 *cam, Culler *culler, float a)
{
if (mc == nullptr || mc->player == nullptr)
{
return;
}
int playerIndex = mc->player->GetXboxPad(); // 4J added
// 4J Stu - Set these up every time, even when not rendering as other things (like particle render) may depend on it for those frames.
@ -524,6 +529,10 @@ void LevelRenderer::renderEntities(Vec3 *cam, Culler *culler, float a)
culledEntities = 0;
shared_ptr<Entity> player = mc->cameraTargetPlayer;
if (player == nullptr)
{
return;
}
EntityRenderDispatcher::xOff = (player->xOld + (player->x - player->xOld) * a);
EntityRenderDispatcher::yOff = (player->yOld + (player->y - player->yOld) * a);
@ -758,12 +767,21 @@ int compare (const void * a, const void * b)
int LevelRenderer::renderChunks(int from, int to, int layer, double alpha)
{
if (mc == nullptr || mc->player == nullptr)
{
return 0;
}
int playerIndex = mc->player->GetXboxPad(); // 4J added
#if 1
// 4J - cut down version, we're not using offsetted render lists, or a sorted chunk list, anymore
mc->gameRenderer->turnOnLightLayer(alpha); // 4J - brought forward from 1.8.2
shared_ptr<LivingEntity> player = mc->cameraTargetPlayer;
if (player == nullptr)
{
return 0;
}
double xOff = player->xOld + (player->x - player->xOld) * alpha;
double yOff = player->yOld + (player->y - player->yOld) * alpha;
double zOff = player->zOld + (player->z - player->zOld) * alpha;

View file

@ -37,8 +37,18 @@ float LivingEntityRenderer::rotlerp(float from, float to, float a)
void LivingEntityRenderer::render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a)
{
if (_mob == nullptr)
{
return;
}
shared_ptr<LivingEntity> mob = dynamic_pointer_cast<LivingEntity>(_mob);
if (mob == nullptr)
{
return;
}
glPushMatrix();
glDisable(GL_CULL_FACE);

View file

@ -15,8 +15,18 @@ MobRenderer::MobRenderer(Model *model, float shadow) : LivingEntityRenderer(mode
void MobRenderer::render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a)
{
if (_mob == nullptr)
{
return;
}
shared_ptr<Mob> mob = dynamic_pointer_cast<Mob>(_mob);
if (mob == nullptr)
{
return;
}
LivingEntityRenderer::render(mob, x, y, z, rot, a);
renderLeash(mob, x, y, z, rot, a);
}

View file

@ -668,7 +668,7 @@ void SonyVoiceChat_Vita::tick()
EnterCriticalSection(&m_csRemoteConnections);
for(size_t i=m_remoteConnections.size()-1;i>=0;i--)
for(int i = (int)m_remoteConnections.size() - 1; i >= 0; i--)
{
if(m_remoteConnections[i]->m_bFlaggedForShutdown)
{

View file

@ -83,6 +83,11 @@ void ParticleEngine::tick()
void ParticleEngine::render(shared_ptr<Entity> player, float a, int list)
{
if (player == nullptr)
{
return;
}
// 4J - change brought forward from 1.2.3
float xa = Camera::xa;
float za = Camera::za;

View file

@ -153,9 +153,15 @@ void PlayerRenderer::prepareSecondPassArmor(shared_ptr<LivingEntity> _player, in
void PlayerRenderer::render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a)
{
if (_mob == nullptr)
{
return;
}
// 4J - dynamic cast required because we aren't using templates/generics in our version
shared_ptr<Player> mob = dynamic_pointer_cast<Player>(_mob);
if(mob == nullptr) return;
if(mob->hasInvisiblePrivilege()) return;
shared_ptr<ItemInstance> item = mob->inventory->getSelected();

View file

@ -131,11 +131,19 @@ Slot *AbstractContainerMenu::getSlotFor(shared_ptr<Container> c, int index)
Slot *AbstractContainerMenu::getSlot(int index)
{
if (index < 0 || index >= static_cast<int>(slots.size()))
{
return nullptr;
}
return slots.at(index);
}
shared_ptr<ItemInstance> AbstractContainerMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex)
{
if (slotIndex < 0 || slotIndex >= static_cast<int>(slots.size()))
{
return nullptr;
}
Slot *slot = slots.at(slotIndex);
if (slot != nullptr)
{
@ -251,7 +259,7 @@ shared_ptr<ItemInstance> AbstractContainerMenu::clicked(int slotIndex, int butto
}
else if (clickType == CLICK_QUICK_MOVE)
{
if (slotIndex < 0) return nullptr;
if (slotIndex < 0 || slotIndex >= static_cast<int>(slots.size())) return nullptr;
Slot *slot = slots.at(slotIndex);
if(slot != nullptr && slot->mayPickup(player))
{
@ -408,6 +416,7 @@ shared_ptr<ItemInstance> AbstractContainerMenu::clicked(int slotIndex, int butto
}
else if (clickType == CLICK_SWAP && buttonNum >= 0 && buttonNum < 9)
{
if (slotIndex < 0 || slotIndex >= static_cast<int>(slots.size())) return nullptr;
Slot *slot = slots.at(slotIndex);
if (slot->mayPickup(player))
{
@ -449,6 +458,7 @@ shared_ptr<ItemInstance> AbstractContainerMenu::clicked(int slotIndex, int butto
}
else if (clickType == CLICK_CLONE && player->abilities.instabuild && inventory->getCarried() == nullptr && slotIndex >= 0)
{
if (slotIndex >= static_cast<int>(slots.size())) return nullptr;
Slot *slot = slots.at(slotIndex);
if (slot != nullptr && slot->hasItem())
{
@ -459,6 +469,7 @@ shared_ptr<ItemInstance> AbstractContainerMenu::clicked(int slotIndex, int butto
}
else if (clickType == CLICK_THROW && inventory->getCarried() == nullptr && slotIndex >= 0)
{
if (slotIndex >= static_cast<int>(slots.size())) return nullptr;
Slot *slot = slots.at(slotIndex);
if (slot != nullptr && slot->hasItem() && slot->mayPickup(player))
{
@ -469,6 +480,7 @@ shared_ptr<ItemInstance> AbstractContainerMenu::clicked(int slotIndex, int butto
}
else if (clickType == CLICK_PICKUP_ALL && slotIndex >= 0)
{
if (slotIndex >= static_cast<int>(slots.size())) return nullptr;
Slot *slot = slots.at(slotIndex);
shared_ptr<ItemInstance> carried = inventory->getCarried();

View file

@ -215,9 +215,18 @@ bool EnchantmentMenu::stillValid(shared_ptr<Player> player)
shared_ptr<ItemInstance> EnchantmentMenu::quickMoveStack(shared_ptr<Player> player, int slotIndex)
{
if (slotIndex < 0 || slotIndex >= static_cast<int>(slots.size()))
{
return nullptr;
}
shared_ptr<ItemInstance> clicked = nullptr;
Slot *slot = slots.at(slotIndex);
Slot *IngredientSlot = slots.at(INGREDIENT_SLOT);
Slot *IngredientSlot = nullptr;
if (INGREDIENT_SLOT >= 0 && INGREDIENT_SLOT < static_cast<int>(slots.size()))
{
IngredientSlot = slots.at(INGREDIENT_SLOT);
}
if (slot != nullptr && slot->hasItem())
{

View file

@ -21,7 +21,12 @@ MerchantRecipeList::~MerchantRecipeList()
MerchantRecipe *MerchantRecipeList::getRecipeFor(shared_ptr<ItemInstance> buyA, shared_ptr<ItemInstance> buyB, int selectionHint)
{
if (selectionHint > 0 && selectionHint < m_recipes.size())
if (buyA == nullptr)
{
return nullptr;
}
if (selectionHint > 0 && selectionHint < static_cast<int>(m_recipes.size()))
{
// attempt to match vs the hint
MerchantRecipe *r = m_recipes.at(selectionHint);
@ -166,6 +171,10 @@ void MerchantRecipeList::push_back(MerchantRecipe *recipe)
MerchantRecipe *MerchantRecipeList::at(size_t index)
{
if (index >= m_recipes.size())
{
return nullptr;
}
return m_recipes.at(index);
}

View file

@ -72,6 +72,10 @@ unordered_set<AttributeInstance *> *ServersideAttributeMap::getSyncableAttribute
for (size_t i = 0; i < atts.size(); i++)
{
AttributeInstance *instance = atts.at(i);
if (instance == nullptr)
{
continue;
}
if (instance->getAttribute()->isClientSyncable())
{