Fixed a couple of segfaults and made Free a seperate function
This commit is contained in:
parent
48a2488477
commit
d412630904
@ -160,6 +160,11 @@ void cChunkBuffer::SetBlocks(const BLOCKTYPE * a_src)
|
|||||||
sizeof(BLOCKTYPE) * segment_length
|
sizeof(BLOCKTYPE) * segment_length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Free(m_Sections[i]);
|
||||||
|
m_Sections[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,11 +190,16 @@ void cChunkBuffer::SetMeta(const NIBBLETYPE * a_src)
|
|||||||
{
|
{
|
||||||
m_Sections[i] = Allocate();
|
m_Sections[i] = Allocate();
|
||||||
memcpy(
|
memcpy(
|
||||||
&m_Sections[i]->m_BlockTypes,
|
&m_Sections[i]->m_BlockMeta,
|
||||||
&a_src[i * segment_length],
|
&a_src[i * segment_length],
|
||||||
sizeof(BLOCKTYPE) * segment_length
|
sizeof(BLOCKTYPE) * segment_length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Free(m_Sections[i]);
|
||||||
|
m_Sections[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,6 +209,7 @@ void cChunkBuffer::SetMeta(const NIBBLETYPE * a_src)
|
|||||||
|
|
||||||
void cChunkBuffer::SetLight(const NIBBLETYPE * a_src)
|
void cChunkBuffer::SetLight(const NIBBLETYPE * a_src)
|
||||||
{
|
{
|
||||||
|
if (!a_src) return;
|
||||||
for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
|
for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
|
||||||
{
|
{
|
||||||
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
|
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
|
||||||
@ -215,11 +226,16 @@ void cChunkBuffer::SetLight(const NIBBLETYPE * a_src)
|
|||||||
{
|
{
|
||||||
m_Sections[i] = Allocate();
|
m_Sections[i] = Allocate();
|
||||||
memcpy(
|
memcpy(
|
||||||
&m_Sections[i]->m_BlockTypes,
|
&m_Sections[i]->m_BlockLight,
|
||||||
&a_src[i * segment_length],
|
&a_src[i * segment_length],
|
||||||
sizeof(BLOCKTYPE) * segment_length
|
sizeof(BLOCKTYPE) * segment_length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Free(m_Sections[i]);
|
||||||
|
m_Sections[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,6 +245,7 @@ void cChunkBuffer::SetLight(const NIBBLETYPE * a_src)
|
|||||||
|
|
||||||
void cChunkBuffer::SetSkyLight (const NIBBLETYPE * a_src)
|
void cChunkBuffer::SetSkyLight (const NIBBLETYPE * a_src)
|
||||||
{
|
{
|
||||||
|
if (!a_src) return;
|
||||||
for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
|
for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
|
||||||
{
|
{
|
||||||
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
|
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
|
||||||
@ -245,11 +262,16 @@ void cChunkBuffer::SetSkyLight (const NIBBLETYPE * a_src)
|
|||||||
{
|
{
|
||||||
m_Sections[i] = Allocate();
|
m_Sections[i] = Allocate();
|
||||||
memcpy(
|
memcpy(
|
||||||
&m_Sections[i]->m_BlockTypes,
|
&m_Sections[i]->m_BlockSkyLight,
|
||||||
&a_src[i * segment_length],
|
&a_src[i * segment_length],
|
||||||
sizeof(BLOCKTYPE) * segment_length
|
sizeof(BLOCKTYPE) * segment_length
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Free(m_Sections[i]);
|
||||||
|
m_Sections[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,3 +285,13 @@ cChunkBuffer::sChunkSection * cChunkBuffer::Allocate() const
|
|||||||
// TODO: use a allocation pool
|
// TODO: use a allocation pool
|
||||||
return new cChunkBuffer::sChunkSection;
|
return new cChunkBuffer::sChunkSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cChunkBuffer::Free(cChunkBuffer::sChunkSection * ptr) const
|
||||||
|
{
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
for (int i = 0; i < CHUNK_SECTION_NUM; i++)
|
for (int i = 0; i < CHUNK_SECTION_NUM; i++)
|
||||||
{
|
{
|
||||||
if(m_Sections[i]) delete m_Sections[i];
|
if(m_Sections[i]) Free(m_Sections[i]);;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public:
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < CHUNK_SECTION_NUM; i++)
|
for (int i = 0; i < CHUNK_SECTION_NUM; i++)
|
||||||
{
|
{
|
||||||
if(m_Sections[i]) delete m_Sections[i];
|
if(m_Sections[i]) Free(m_Sections[i]);;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IsOwner = true;
|
IsOwner = true;
|
||||||
@ -76,7 +76,7 @@ public:
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < CHUNK_SECTION_NUM; i++)
|
for (int i = 0; i < CHUNK_SECTION_NUM; i++)
|
||||||
{
|
{
|
||||||
if(m_Sections[i]) delete m_Sections[i];
|
if(m_Sections[i]) Free(m_Sections[i]);;
|
||||||
m_Sections[i] = other.m_Sections[i];
|
m_Sections[i] = other.m_Sections[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,6 +239,7 @@ private:
|
|||||||
sChunkSection *m_Sections[CHUNK_SECTION_NUM];
|
sChunkSection *m_Sections[CHUNK_SECTION_NUM];
|
||||||
|
|
||||||
sChunkSection * Allocate() const;
|
sChunkSection * Allocate() const;
|
||||||
|
void Free(sChunkSection * ptr) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user