Make sure we are retrieving tile data safely from the array by doing boundary checks

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 3c608515a8
commit 9ca6ebeeb8
  1. BIN
      C++ProjectTemplate
  2. 1
      SeasonI.h
  3. BIN
      assets/terrainmap.xcf
  4. 10
      main.cpp
  5. 2
      save0

Binary file not shown.

@ -139,6 +139,7 @@ class SeasonI:public PixelGameEngine{
std::string ReadStringFromStream(std::ifstream&f);
void CenterCameraOnPlayer();
int GetPointQuadrantRelativeToLine(vi2d x1y1,vi2d x2y2,vi2d point);
TILE GetSafeTileData(std::vector<std::vector<TILE*>>&data);
char GetTileDegreeSafely(std::vector<std::vector<TILE*>>&data);
};
extern SeasonI*GAME;

Binary file not shown.

@ -4587,7 +4587,7 @@ void SeasonI::DrawGameWorld() {
int yTileOffset = cameraPos.y/32;
for (auto&obj:OBJECTS) {
if (!obj->drawn&&(!obj->dead||EDITING_LAYER==layer::ENCOUNTER)&&
(GetTileDegreeSafely(MAP2)&&
(GetTileDegreeSafely(MAP2)==0&&
obj->GetPos().y+obj->originPoint.y>(y+yTileOffset)*32&&
obj->GetPos().y+obj->originPoint.y<=(y+yTileOffset+1)*32)) {
obj->drawn=true;
@ -5546,10 +5546,16 @@ int SeasonI::GetPointQuadrantRelativeToLine(vi2d x1y1,vi2d x2y2,vi2d point){
return (x2y2.y - x1y1.y) * point.x + (x1y1.x - x2y2.x) * point.y + (x2y2.x * x1y1.y - x1y1.x * x2y2.y);
}
TILE SeasonI::GetSafeTileData(std::vector<std::vector<TILE*>>&data){
int tileY=(int)PARTY_MEMBER_OBJ[0]->GetPosWithOrigin().y/32;
int tileX=(int)PARTY_MEMBER_OBJ[0]->GetPosWithOrigin().x/32;
return tileX>=0&&tileY>=0&&tileX<data[0].size()&&tileY<data.size()?*data[(int)PARTY_MEMBER_OBJ[0]->GetPosWithOrigin().y/32][(int)PARTY_MEMBER_OBJ[0]->GetPosWithOrigin().x/32]:TILE(0,0,0);
}
char SeasonI::GetTileDegreeSafely(std::vector<std::vector<TILE*>>&data){
int tileY=(int)PARTY_MEMBER_OBJ[0]->GetPosWithOrigin().y/32;
int tileX=(int)PARTY_MEMBER_OBJ[0]->GetPosWithOrigin().x/32;
return tileX>=0&&tileY>=0&&tileX<data[0].size()&&tileY<data.size()?data[(int)PARTY_MEMBER_OBJ[0]->GetPosWithOrigin().y/32][(int)PARTY_MEMBER_OBJ[0]->GetPosWithOrigin().x/32]->tileDegree:0;
return GetSafeTileData(data).tileDegree;
}
#ifndef TEST_SUITE

@ -1 +1 @@
120 120 PLAYER 30 30 8 8 4 0 0 0 0 0 0 0 11 9 10 13 14 15 16 17 33 29 21 25 1 4 6 3 4 7 8 3590.34 279.648 120 120 NESS 30 30 8 8 4 0 0 0 0 0 0 0 6 33 34 29 30 31 32 0 3 -1 7 12 3590.34 266.648 120 120 PAULA 30 30 8 8 4 0 0 0 0 0 0 0 6 21 22 23 24 37 38 0 3 -1 7 -1 3592.34 256.648 120 120 JEFF 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 120 120 ANNA 30 30 8 8 4 0 0 0 0 0 0 0 4 21 25 26 29 0 3 5 7 12 3592.34 244.648 120 120 KING 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 120 120 POO 30 30 8 8 4 0 0 0 0 0 0 0 1 0 0 3 -1 -1 -1 -999 -999 47 6 7 7 7 7 7 7 7 7 7 7 6 3 3 3 10 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 11 0 0 512 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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