Répare la désallocation.
This commit is contained in:
parent
e044a98359
commit
57b7560a46
@ -44,6 +44,9 @@ GridTeamH& GridTeamH::operator=(GridTeamH const& cpy)
|
|||||||
mHeight = cpy.mHeight;
|
mHeight = cpy.mHeight;
|
||||||
mAliveCount = cpy.mAliveCount;
|
mAliveCount = cpy.mAliveCount;
|
||||||
|
|
||||||
|
mData = new CellType[mWidth * mHeight];
|
||||||
|
mIntermediateData = new CellType[mWidth * mHeight];
|
||||||
|
|
||||||
memcpy(mData, cpy.mData, cpy.size() * sizeof(CellType));
|
memcpy(mData, cpy.mData, cpy.size() * sizeof(CellType));
|
||||||
memcpy(mIntermediateData, cpy.mIntermediateData, cpy.size() * sizeof(CellType));
|
memcpy(mIntermediateData, cpy.mIntermediateData, cpy.size() * sizeof(CellType));
|
||||||
}
|
}
|
||||||
@ -81,9 +84,7 @@ GridTeamH::~GridTeamH()
|
|||||||
// Mutateur modifiant la taille de la grille et initialise le contenu par la valeur spécifiée.
|
// Mutateur modifiant la taille de la grille et initialise le contenu par la valeur spécifiée.
|
||||||
void GridTeamH::resize(size_t width, size_t height, CellType initValue)
|
void GridTeamH::resize(size_t width, size_t height, CellType initValue)
|
||||||
{
|
{
|
||||||
// On exige que si mData soit null, mIntermediateData le soit aussi.
|
dealloc();
|
||||||
if (mData)
|
|
||||||
dealloc();
|
|
||||||
|
|
||||||
mWidth = width;
|
mWidth = width;
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
@ -94,12 +95,14 @@ void GridTeamH::resize(size_t width, size_t height, CellType initValue)
|
|||||||
fill(initValue, true);
|
fill(initValue, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridTeamH::dealloc() const
|
void GridTeamH::dealloc()
|
||||||
{
|
{
|
||||||
if (mData && mIntermediateData) {
|
if (mData && mIntermediateData) {
|
||||||
delete[] mData;
|
delete[] mData;
|
||||||
delete[] mIntermediateData;
|
delete[] mIntermediateData;
|
||||||
}
|
}
|
||||||
|
mData = nullptr;
|
||||||
|
mIntermediateData = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accesseur retournant la valeur d'une cellule à une certaine coordonnée.
|
// Accesseur retournant la valeur d'une cellule à une certaine coordonnée.
|
||||||
|
@ -96,7 +96,7 @@ private:
|
|||||||
std::uniform_real_distribution<> mDistribution;
|
std::uniform_real_distribution<> mDistribution;
|
||||||
|
|
||||||
void fillBorderManipulations(DataType ptr, CellType value) const;
|
void fillBorderManipulations(DataType ptr, CellType value) const;
|
||||||
void dealloc() const;
|
void dealloc();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif GRIDTEAMH_H
|
#endif GRIDTEAMH_H
|
Loading…
Reference in New Issue
Block a user