Fix SEGV when top part of the map is empty

This commit is contained in:
Rogier 2014-05-12 10:41:23 +02:00
parent f36a8b61fb
commit 3df8be20bb
2 changed files with 14 additions and 6 deletions

View File

@ -50,7 +50,7 @@ public:
void scroll(int keepY);
PixelAttribute &attribute(int y, int x);
void renderShading(bool drawAlpha);
void setLastY(int y) { m_lastY = y; }
void setLastY(int y);
int getLastY(void) { return m_lastY; }
private:
@ -70,6 +70,17 @@ private:
int m_firstUnshadedY;
};
inline void PixelAttributes::setLastY(int y)
{
#ifdef DEBUG
assert(y - m_firstY <= m_lastLine - m_firstLine);
#else
if (y - m_firstY > m_lastLine - m_firstLine)
// Not sure whether this will actually avoid a crash...
y = m_firstY + (m_lastLine - m_firstLine);
#endif
m_lastY = y;
}
inline PixelAttribute &PixelAttributes::attribute(int y, int x)
{

View File

@ -645,10 +645,8 @@ void TileGenerator::pushPixelRows(int zPosLimit) {
m_image->tpixels[mapY2ImageY(mapY)][mapX2ImageX(mapX)] = pixel.color().to_libgd();
}
}
m_nextStoredYCoord = y;
m_blockPixelAttributes.scroll(y);
int yLimit = worldBlockZ2StoredY(zPosLimit);
if (y < yLimit) {
if (y <= yLimit) {
m_blockPixelAttributes.scroll(yLimit);
m_nextStoredYCoord = yLimit;
}
@ -843,8 +841,7 @@ void TileGenerator::renderMap()
if (currentPos.x != pos.x || currentPos.z != pos.z) {
area_rendered++;
if (currentPos.z != pos.z) {
if (currentPos.z != INT_MIN)
pushPixelRows(pos.z);
pushPixelRows(pos.z);
m_blockPixelAttributes.setLastY((m_zMax - pos.z) * 16 + 15);
if (progressIndicator)
cout << "Processing Z-coordinate: " << std::setw(5) << pos.z*16 << "\r" << std::flush;