1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-18 13:12:50 +00:00

crashfix on game exit

This commit is contained in:
florent.teppe 2022-09-12 19:13:02 +02:00
parent 7e6011751c
commit 565a08b95a
2 changed files with 21 additions and 9 deletions

View File

@ -258,7 +258,7 @@ namespace Debug
ext->glUniform1i(normalAsColorLocation, false);
for (const auto& shapeToDraw : mShapesToDraw)
for (const auto& shapeToDraw : *mShapesToDraw)
{
osg::Vec3f translation = shapeToDraw.mPosition;
osg::Vec3f color = shapeToDraw.mColor;
@ -281,7 +281,7 @@ namespace Debug
break;
}
}
mShapesToDraw.clear();
mShapesToDraw->clear();
static_cast<osg::Vec3Array*>(mLinesToDraw->getVertexArray())->clear();
static_cast<osg::Vec3Array*>(mLinesToDraw->getNormalArray())->clear();
}
@ -377,6 +377,8 @@ Debug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_p
for (std::size_t i = 0; i < mShapesToDraw.size(); i++)
{
mShapesToDraw[i] = std::make_shared<std::vector<DrawCall>>();
mCustomDebugDrawer[i] = new DebugCustomDraw(mShapesToDraw[i], mDebugLines->mLinesGeom[i]);
mCustomDebugDrawer[i]->setStateSet(stateset);
mCustomDebugDrawer[i]->mWireCubeGeometry = wireCube;
@ -390,11 +392,17 @@ Debug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_p
Debug::DebugDrawer::~DebugDrawer()
{
}
auto parentsList = mDebugDrawSceneObjects->getParents();
for (auto parent : parentsList)
{
parent->removeChild(mDebugDrawSceneObjects);
}
}
void Debug::DebugDrawer::drawCube(osg::Vec3f mPosition, osg::Vec3f mDims, osg::Vec3f mColor)
{
mShapesToDraw[getIdexBufferWriteFromFrame(this->mCurrentFrame)].push_back({ mPosition, mDims, mColor, DrawShape::Cube });
mShapesToDraw[getIdexBufferWriteFromFrame(this->mCurrentFrame)]->push_back({ mPosition, mDims, mColor, DrawShape::Cube });
}
void Debug::DebugDrawer::drawCubeMinMax(osg::Vec3f min, osg::Vec3f max, osg::Vec3f color)
@ -406,7 +414,7 @@ void Debug::DebugDrawer::drawCubeMinMax(osg::Vec3f min, osg::Vec3f max, osg::Vec
void Debug::DebugDrawer::addDrawCall(const DrawCall& draw)
{
mShapesToDraw[getIdexBufferWriteFromFrame(this->mCurrentFrame)].push_back(draw);
mShapesToDraw[getIdexBufferWriteFromFrame(this->mCurrentFrame)]->push_back(draw);
}
void Debug::DebugDrawer::addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color)

View File

@ -58,10 +58,14 @@ namespace Debug
class DebugCustomDraw : public osg::Drawable
{
public:
DebugCustomDraw(std::vector<DrawCall>& cubesToDraw, osg::ref_ptr<osg::Geometry>& linesToDraw) : mShapesToDraw(cubesToDraw), mLinesToDraw(linesToDraw) {}
DebugCustomDraw(std::shared_ptr<std::vector<DrawCall>> cubesToDraw, osg::ref_ptr<osg::Geometry>& linesToDraw)
: mShapesToDraw(cubesToDraw)
, mLinesToDraw(linesToDraw)
{
}
std::vector<DrawCall>& mShapesToDraw;
osg::ref_ptr<osg::Geometry>& mLinesToDraw;
std::shared_ptr<std::vector<DrawCall>> mShapesToDraw;
osg::ref_ptr<osg::Geometry> mLinesToDraw;
osg::ref_ptr<osg::Geometry> mCubeGeometry;
osg::ref_ptr<osg::Geometry> mCylinderGeometry;
@ -87,7 +91,7 @@ namespace Debug
private:
std::unique_ptr<DebugLines> mDebugLines;
std::array<std::vector<DrawCall>, 2> mShapesToDraw;
std::array<std::shared_ptr<std::vector<DrawCall>>, 2> mShapesToDraw;
long long int mCurrentFrame;
std::array<osg::ref_ptr<DebugCustomDraw>, 2> mCustomDebugDrawer;