Skip to content

Commit ccd9993

Browse files
committed
ovis: allow re-initialization by destroying all windows
1 parent 01f00f8 commit ccd9993

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

modules/ovis/src/ovis.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ struct Application : public OgreBites::ApplicationContext, public OgreBites::Inp
236236
return ret;
237237
}
238238

239+
size_t numWindows() const { return mWindows.size(); }
240+
239241
void locateResources() CV_OVERRIDE
240242
{
241243
OgreBites::ApplicationContext::locateResources();
@@ -277,9 +279,10 @@ class WindowSceneImpl : public WindowScene
277279
Ptr<Rectangle2D> bgplane;
278280

279281
Ogre::RenderTarget* depthRTT;
282+
int flags;
280283
public:
281-
WindowSceneImpl(Ptr<Application> app, const String& _title, const Size& sz, int flags)
282-
: title(_title), root(app->getRoot()), depthRTT(NULL)
284+
WindowSceneImpl(Ptr<Application> app, const String& _title, const Size& sz, int _flags)
285+
: title(_title), root(app->getRoot()), depthRTT(NULL), flags(_flags)
283286
{
284287
if (!app->sceneMgr)
285288
{
@@ -337,6 +340,25 @@ class WindowSceneImpl : public WindowScene
337340
rWin->addViewport(cam);
338341
}
339342

343+
~WindowSceneImpl()
344+
{
345+
if (flags & SCENE_SEPERATE)
346+
{
347+
MaterialManager::getSingleton().remove(bgplane->getMaterial());
348+
bgplane.release();
349+
String texName = sceneMgr->getName() + "_Background";
350+
TextureManager::getSingleton().remove(texName, RESOURCEGROUP_NAME);
351+
}
352+
353+
if(_app->sceneMgr == sceneMgr && (flags & SCENE_SEPERATE))
354+
{
355+
// this is the root window owning the context
356+
CV_Assert(_app->numWindows() == 1 && "the first OVIS window must be deleted last");
357+
_app->closeApp();
358+
_app.release();
359+
}
360+
}
361+
340362
void setBackground(InputArray image) CV_OVERRIDE
341363
{
342364
CV_Assert(bgplane);

0 commit comments

Comments
 (0)