Browse Source

fix memory access violation when transmitting chunk light data to client

Kolja Strohm 1 tháng trước cách đây
mục cha
commit
5ce14721e2
1 tập tin đã thay đổi với 7 bổ sung10 xóa
  1. 7 10
      FactoryCraft/Chunk.cpp

+ 7 - 10
FactoryCraft/Chunk.cpp

@@ -279,7 +279,7 @@ void Chunk::sendLightToClient(
         {
             for (int y = -1; y <= CHUNK_SIZE; y++)
             {
-                if ((x < 0 || x == CHUNK_SIZE) && (y < 0 || y > CHUNK_SIZE))
+                if ((x < 0 || x == CHUNK_SIZE) && (y < 0 || y == CHUNK_SIZE))
                 {
                     continue;
                 }
@@ -296,30 +296,27 @@ void Chunk::sendLightToClient(
                     {
                         int dir;
                         int index = 0;
+                        int tmpX = x;
+                        int tmpY = y;
+                        index = (((x + CHUNK_SIZE) % CHUNK_SIZE) * CHUNK_SIZE
+                                    + ((y + CHUNK_SIZE) % CHUNK_SIZE))
+                                  * WORLD_HEIGHT
+                              + z;
                         if (x == -1)
                         {
                             dir = getDirectionIndex(WEST);
-                            index = ((CHUNK_SIZE - 1) * CHUNK_SIZE + y)
-                                      * WORLD_HEIGHT
-                                  + z;
                         }
                         else if (y == -1)
                         {
                             dir = getDirectionIndex(NORTH);
-                            index = (x * CHUNK_SIZE + CHUNK_SIZE - 1)
-
-                                      * WORLD_HEIGHT
-                                  + z;
                         }
                         else if (x == CHUNK_SIZE)
                         {
                             dir = getDirectionIndex(EAST);
-                            index = y * WORLD_HEIGHT + z;
                         }
                         else if (y == CHUNK_SIZE)
                         {
                             dir = getDirectionIndex(SOUTH);
-                            index = (x * CHUNK_SIZE) * WORLD_HEIGHT + z;
                         }
                         if (zNeighbours[dir])
                         {