Revert "Replace raw pointer by observer_ptr to avoid dangling pointer dereferencing"

This reverts commit 5373cf1cd5.
pull/3093/head
Andrei Kortunov 4 years ago
parent b583c2300c
commit c54ef55ebb

@ -726,7 +726,7 @@ namespace SceneUtil
META_StateAttribute(NifOsg, LightManagerStateAttribute, osg::StateAttribute::LIGHT) META_StateAttribute(NifOsg, LightManagerStateAttribute, osg::StateAttribute::LIGHT)
void initSharedLayout(osg::GLExtensions* ext, int handle, LightManager& lightManager) const void initSharedLayout(osg::GLExtensions* ext, int handle) const
{ {
constexpr std::array<unsigned int, 1> index = { static_cast<unsigned int>(Shader::UBOBinding::LightBuffer) }; constexpr std::array<unsigned int, 1> index = { static_cast<unsigned int>(Shader::UBOBinding::LightBuffer) };
int totalBlockSize = -1; int totalBlockSize = -1;
@ -748,17 +748,13 @@ namespace SceneUtil
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
{ {
auto& buf = lightManager.getLightBuffer(i); auto& buf = mLightManager->getLightBuffer(i);
buf = new LightBuffer(*buf, offsets[0], offsets[1], offsets[2], totalBlockSize, stride); buf = new LightBuffer(*buf, offsets[0], offsets[1], offsets[2], totalBlockSize, stride);
} }
} }
void apply(osg::State& state) const override void apply(osg::State& state) const override
{ {
osg::ref_ptr<LightManager> lightManager;
if (!mLightManager.lock(lightManager))
return;
if (!mInitLayout) if (!mInitLayout)
{ {
mDummyProgram->apply(state); mDummyProgram->apply(state);
@ -771,12 +767,12 @@ namespace SceneUtil
// wait until the UBO binding is created // wait until the UBO binding is created
if (activeUniformBlocks > 0) if (activeUniformBlocks > 0)
{ {
initSharedLayout(ext, handle, *lightManager); initSharedLayout(ext, handle);
mInitLayout = true; mInitLayout = true;
} }
} }
lightManager->getLightBuffer(state.getFrameStamp()->getFrameNumber())->uploadCachedSunPos(state.getInitialViewMatrix()); mLightManager->getLightBuffer(state.getFrameStamp()->getFrameNumber())->uploadCachedSunPos(state.getInitialViewMatrix());
lightManager->getLightBuffer(state.getFrameStamp()->getFrameNumber())->dirty(); mLightManager->getLightBuffer(state.getFrameStamp()->getFrameNumber())->dirty();
} }
private: private:
@ -806,7 +802,7 @@ namespace SceneUtil
return shader; return shader;
} }
osg::observer_ptr<LightManager> mLightManager; LightManager* mLightManager;
osg::ref_ptr<osg::Program> mDummyProgram; osg::ref_ptr<osg::Program> mDummyProgram;
mutable bool mInitLayout; mutable bool mInitLayout;
}; };

Loading…
Cancel
Save