Discussion:
[osg-users] porting from osg-3.4.0 to osg-3.6.3
Herman Varma
2018-10-07 17:21:20 UTC
Permalink
Hi Robert

I followed your advice and used the Simple app in VTP with Debug statements.
I compared the debug statements wit those osg-3.4.0.

I was able to track it down to this section

while (!viewer->done())
{
vtGetScene()->DoUpdate(); // calls
viewer::frame
}
In 3.4.0 it executes and in 3.6.3 it bombs on

vtGetScene()->DoUpdate();


DoUpdate() is defined by vs2017 as void VTScene::DoUpdate() backward
compatibility

Also
viewer->done() value has a bool value of 0 at the bomb instant.


Full code below

int main(int argc, char ** argv)
{
#if WIN32 && defined(_MSC_VER) && VTDEBUG
// sometimes, MSVC seems to need to be told to show unfreed memory
on exit
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

// Log messages to make troubleshooting easier
VTSTARTLOG("debug.txt");
VTLOG("osgViewerSimple\n");

// Make a scene and a viewer:
vtGetScene()->Init(argc, argv);
osgViewer::Viewer *viewer = vtGetScene()->getViewer();

// Add a handler for GUI events.
osg::ref_ptr<vtOSGEventHandler> pHandler = new vtOSGEventHandler;
viewer->addEventHandler(pHandler);

// We must call realize to be certain that a display/context is set
up.
viewer->realize();

// Tell our scene about OSG's context.

vtGetScene()->SetGraphicsContext(viewer->getCamera()->getGraphicsContext());

// Only then can we safely get window size.
vtGetScene()->GetWindowSizeFromOSG();

printf("Creating the terrain..\n");
CreateScene();

printf("Running..\n");

VTLOG("Getscene Loop %d\n", (int)viewer->done());

while (!viewer->done())
{
vtGetScene()->DoUpdate(); // calls
viewer::frame
}

VTLOG("Done Updatescene.\n");

g_terrscene->CleanupScene();
delete g_terrscene;

vtGetScene()->Shutdown();

return 0;
}


Thanks
------------------------------

Message: 2
Date: Thu, 04 Oct 2018 15:31:14 +0200
From: "Herman Varma" <***@eastlink.ca>
To: osg-***@lists.openscenegraph.org
Subject: Re: [osg-users] Problems porting from osg-3.4.0 to osg-3.6.0
Message-ID: <***@forum.openscenegraph.org>
Content-Type: text/plain; charset=UTF-8

Hi,


I have upgraded the vtp code to osg 3.6.3
Everything compiled and linked properly. However I still have some execution
problems.

I just want to check if the code below is coded properly

FQuat TransformExtension::GetOrient() const
{
const osg::Matrix &xform = m_pTransform->getMatrix();
osg::Quat q;

// xform.get(q);
// Replacing xform.get(q)
// with
q = xform.getRotate();

return FQuat(q.x(), q.y(), q.z(), q.w());
}

...

Thank you!

Cheers,
Herman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75036#75036







------------------------------

Subject: Digest Footer

_______________________________________________
osg-users mailing list
osg-***@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------------------

End of osg-users Digest, Vol 136, Issue 4
*****************************************
Robert Osfield
2018-10-08 07:47:29 UTC
Permalink
Hi Herman,

From the details provided there isn't anything we suggest, the only
thing we can do is suggest that you provide more information.

The first thing would be to post a stack trace, at least then we might
have an idea what bit of code is failing and with what error.

Robert.
Post by Herman Varma
Hi Robert
I followed your advice and used the Simple app in VTP with Debug statements.
I compared the debug statements wit those osg-3.4.0.
I was able to track it down to this section
while (!viewer->done())
{
vtGetScene()->DoUpdate(); // calls
viewer::frame
}
In 3.4.0 it executes and in 3.6.3 it bombs on
vtGetScene()->DoUpdate();
DoUpdate() is defined by vs2017 as void VTScene::DoUpdate() backward
compatibility
Also
viewer->done() value has a bool value of 0 at the bomb instant.
Full code below
int main(int argc, char ** argv)
{
#if WIN32 && defined(_MSC_VER) && VTDEBUG
// sometimes, MSVC seems to need to be told to show unfreed memory
on exit
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
// Log messages to make troubleshooting easier
VTSTARTLOG("debug.txt");
VTLOG("osgViewerSimple\n");
vtGetScene()->Init(argc, argv);
osgViewer::Viewer *viewer = vtGetScene()->getViewer();
// Add a handler for GUI events.
osg::ref_ptr<vtOSGEventHandler> pHandler = new vtOSGEventHandler;
viewer->addEventHandler(pHandler);
// We must call realize to be certain that a display/context is set
up.
viewer->realize();
// Tell our scene about OSG's context.
vtGetScene()->SetGraphicsContext(viewer->getCamera()->getGraphicsContext());
// Only then can we safely get window size.
vtGetScene()->GetWindowSizeFromOSG();
printf("Creating the terrain..\n");
CreateScene();
printf("Running..\n");
VTLOG("Getscene Loop %d\n", (int)viewer->done());
while (!viewer->done())
{
vtGetScene()->DoUpdate(); // calls
viewer::frame
}
VTLOG("Done Updatescene.\n");
g_terrscene->CleanupScene();
delete g_terrscene;
vtGetScene()->Shutdown();
return 0;
}
Thanks
------------------------------
Message: 2
Date: Thu, 04 Oct 2018 15:31:14 +0200
Subject: Re: [osg-users] Problems porting from osg-3.4.0 to osg-3.6.0
Content-Type: text/plain; charset=UTF-8
Hi,
I have upgraded the vtp code to osg 3.6.3
Everything compiled and linked properly. However I still have some execution
problems.
I just want to check if the code below is coded properly
FQuat TransformExtension::GetOrient() const
{
const osg::Matrix &xform = m_pTransform->getMatrix();
osg::Quat q;
// xform.get(q);
// Replacing xform.get(q)
// with
q = xform.getRotate();
return FQuat(q.x(), q.y(), q.z(), q.w());
}
...
Thank you!
Cheers,
Herman
------------------
http://forum.openscenegraph.org/viewtopic.php?p=75036#75036
------------------------------
Subject: Digest Footer
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
------------------------------
End of osg-users Digest, Vol 136, Issue 4
*****************************************
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Herman Varma
2018-10-08 19:38:59 UTC
Permalink
Hi,
Hi Robert



I down down further to this statement

m_pOsgViewer->frame();//

In 3.4.0 it executes and in 3.6.3 it bombs here


The full code is posted below
void vtScene::UpdateWindow(vtWindow *pWindow)
{
if (!m_bInitialized) return;

// window background color
osg::Vec4 color2;
v2s(pWindow->GetBgColor(), color2);
m_pOsgViewer->getCamera()->setClearColor(color2);

// window size
IPoint2 winsize = pWindow->GetSize();
if (winsize.x == 0 || winsize.y == 0)
{
VTLOG("Warning: winsize %d %d\n", winsize.x, winsize.y);
return;
}
m_pOsgViewer->getCamera()->setViewport(0, 0, winsize.x, winsize.y);

// As of OSG 0.9.5, we need to store our own camera params and recreate
// the projection matrix each frame.
float aspect;
if (winsize.x == 0 || winsize.y == 0) // safety
aspect = 1.0;
else
aspect = (float) winsize.x / winsize.y;

if (m_pCamera->IsOrtho())
{
// Arguments are left, right, bottom, top, zNear, zFar
float w2 = m_pCamera->GetWidth() /2;
float h2 = w2 / aspect;
m_pOsgViewer->getCamera()->setProjectionMatrixAsOrtho(-w2, w2, -h2, h2,
m_pCamera->GetHither(), m_pCamera->GetYon());
}
else
{
float fov_x = m_pCamera->GetFOV();
float a = tan (fov_x/2);
float b = a / aspect;
float fov_y_div2 = atan(b);
float fov_y_deg = osg::RadiansToDegrees(fov_y_div2 * 2);

m_pOsgViewer->getCamera()->setProjectionMatrixAsPerspective(fov_y_deg,
aspect, m_pCamera->GetHither(), m_pCamera->GetYon());
}


// And apply the rotation and translation of the camera itself
const osg::Matrix &mat2 = m_pCamera->getMatrix();
osg::Matrix imat;


imat.invert(mat2);

m_pOsgViewer->getCamera()->setViewMatrix(imat);
m_pOsgViewer->getCamera()->setCullMask(0x3);
// Also set the mask for the case of split-screen stereo
m_pOsgViewer->getCamera()->setCullMaskLeft(0x3);
m_pOsgViewer->getCamera()->setCullMaskRight(0x3);

m_pOsgViewer->frame();// ***************************It bombs on this statement


}

I also ran it in debug mode and posted a diagnostic.jpg of the resulting
debug screen

Thank you!

Cheers,
Herman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75049#75049




Attachments:
Loading Image...
Robert Osfield
2018-10-09 06:29:28 UTC
Permalink
Hi Herman,

Thanks for the stack trace, the crash site and value of nv suggest
that for some reason the application is setting up the viewer without
an EventVIsitior. The osgViewer assigns one by default so this must
have been reset, or the call to handle customized in some way that is
non-standard.

Have a look for any places where setEventVisitor is called in VTP.

Robert.
Post by Herman Varma
Hi,
Hi Robert
I down down further to this statement
m_pOsgViewer->frame();//
In 3.4.0 it executes and in 3.6.3 it bombs here
The full code is posted below
void vtScene::UpdateWindow(vtWindow *pWindow)
{
if (!m_bInitialized) return;
// window background color
osg::Vec4 color2;
v2s(pWindow->GetBgColor(), color2);
m_pOsgViewer->getCamera()->setClearColor(color2);
// window size
IPoint2 winsize = pWindow->GetSize();
if (winsize.x == 0 || winsize.y == 0)
{
VTLOG("Warning: winsize %d %d\n", winsize.x, winsize.y);
return;
}
m_pOsgViewer->getCamera()->setViewport(0, 0, winsize.x, winsize.y);
// As of OSG 0.9.5, we need to store our own camera params and recreate
// the projection matrix each frame.
float aspect;
if (winsize.x == 0 || winsize.y == 0) // safety
aspect = 1.0;
else
aspect = (float) winsize.x / winsize.y;
if (m_pCamera->IsOrtho())
{
// Arguments are left, right, bottom, top, zNear, zFar
float w2 = m_pCamera->GetWidth() /2;
float h2 = w2 / aspect;
m_pOsgViewer->getCamera()->setProjectionMatrixAsOrtho(-w2, w2, -h2, h2,
m_pCamera->GetHither(), m_pCamera->GetYon());
}
else
{
float fov_x = m_pCamera->GetFOV();
float a = tan (fov_x/2);
float b = a / aspect;
float fov_y_div2 = atan(b);
float fov_y_deg = osg::RadiansToDegrees(fov_y_div2 * 2);
m_pOsgViewer->getCamera()->setProjectionMatrixAsPerspective(fov_y_deg,
aspect, m_pCamera->GetHither(), m_pCamera->GetYon());
}
// And apply the rotation and translation of the camera itself
const osg::Matrix &mat2 = m_pCamera->getMatrix();
osg::Matrix imat;
imat.invert(mat2);
m_pOsgViewer->getCamera()->setViewMatrix(imat);
m_pOsgViewer->getCamera()->setCullMask(0x3);
// Also set the mask for the case of split-screen stereo
m_pOsgViewer->getCamera()->setCullMaskLeft(0x3);
m_pOsgViewer->getCamera()->setCullMaskRight(0x3);
m_pOsgViewer->frame();// ***************************It bombs on this statement
}
I also ran it in debug mode and posted a diagnostic.jpg of the resulting
debug screen
Thank you!
Cheers,
Herman
------------------
http://forum.openscenegraph.org/viewtopic.php?p=75049#75049
http://forum.openscenegraph.org//files/diagnostic_569.jpg
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Herman Varma
2018-10-09 13:49:43 UTC
Permalink
Hi Robert


Yes VTP calls setEventVisitor

m_pOsgViewer->setEventVisitor(NULL);

in
bool vtScene::Init(int argc, char** argv, bool bStereo, int iStereoMode)

Code is listed below marked as //*******CALLED HERE





/**
* Initialize the vtlib library, including the display and scene graph.
* You should call this function only once, before any other vtlib calls.
*
* \param argc, argv Command-line arguments.
* \param bStereo True for a stereo display output.
* \param iStereoMode Currently for vtosg, supported values are 0 for
* Anaglyphic (red-blue) and 1 for Quad-buffer (shutter glasses).
*/
bool vtScene::Init(int argc, char** argv, bool bStereo, int iStereoMode)
{
VTLOG1("vtScene::Init\n");

// Redirect cout messages (where OSG sends its messages) to our own log
previous_cout = std::cout.rdbuf(&g_Trap);
previous_cerr = std::cerr.rdbuf(&g_Trap);

#if 0
// If you encounter trouble in OSG that you want to debug, enable this
// to get a LOT of diagnostic messages from OSG.
osg::setNotifyLevel(osg::INFO);
#endif

m_pDefaultCamera = new vtCamera;
m_pDefaultWindow = new vtWindow;
SetCamera(m_pDefaultCamera);
AddWindow(m_pDefaultWindow);

// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);

m_pOsgViewer = new osgViewer::Viewer(arguments);

m_pOsgViewer->setDisplaySettings(osg::DisplaySettings::instance());
if (bStereo)
{
osg::DisplaySettings* displaySettings = m_pOsgViewer->getDisplaySettings();
displaySettings->setStereo(true);
osg::DisplaySettings::StereoMode mode;
if (iStereoMode == 0) mode = osg::DisplaySettings::ANAGLYPHIC;
if (iStereoMode == 1) mode = osg::DisplaySettings::QUAD_BUFFER;
if (iStereoMode == 2) mode = osg::DisplaySettings::HORIZONTAL_SPLIT;
if (iStereoMode == 3) mode = osg::DisplaySettings::VERTICAL_SPLIT;
displaySettings->setStereoMode(mode);
}
#ifdef __DARWIN_OSX__
// Kill multi-threading on OSX until wxGLContext properly implemented on that platform
m_pOsgViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
#endif

// We can't use displaySettings->setNumMultiSamples here to enable anti-
// aliasing, because it has to be done eariler (at the time the OpenGL
// context is made).

#ifdef VTP_USE_OSG_STATS
osgViewer::StatsHandler* pStatsHandler = new osgViewer::StatsHandler;
pStatsHandler->setKeyEventPrintsOutStats(0);
pStatsHandler->setKeyEventTogglesOnScreenStats('x'); // I dont think this is used for anything else at the moment
m_pOsgViewer->addEventHandler(pStatsHandler);
#endif

// Kill the event visitor (saves a scenegraph traversal)
// This will need to be restored if we need to use FRAME events etc. in the scenegraph
m_pOsgViewer->setEventVisitor(NULL);//*******CALLED HERE

if (bStereo)
{
// displaySettings->getScreenDistance(); default is 0.5
// m_pOsgSceneView->getFusionDistanceMode(); default is PROPORTIONAL_TO_SCREEN_DISTANCE
// m_pOsgSceneView->getFusionDistanceValue(); default is 1.0
// The FusionDistanceValue is only used for USE_FUSION_DISTANCE_VALUE & PROPORTIONAL_TO_SCREEN_DISTANCE modes.

// We use real-world units for fusion distance value
m_pOsgViewer->setFusionDistance(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE, 100.0f);
}

// From the OSG mailing list: You must specify the lighting mode in
// setDefaults() and override the default options. If you call
// setDefaults() with the default options, a headlight is added to the
// global state set of the SceneView. With the default options applied,
// I have tried subsequently calling setLightingMode(NO_SCENE_LIGHT)
// and setLight(NULL), but I still get a headlight.
m_pOsgViewer->setLightingMode(osg::View::NO_LIGHT);
m_pOsgViewer->getCamera()->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
m_pOsgViewer->getCamera()->setCullingMode(m_pOsgViewer->getCamera()->getCullingMode() & ~osg::CullSettings::SMALL_FEATURE_CULLING);

// We maintain a node between OSG's viewer/camera and the vtlib Root, to
// control global state
m_StateRoot = new osg::Group;
m_pOsgViewer->setSceneData(m_StateRoot);

// By default, things are lit, unless they ask not to be
m_StateRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);

//m_StateRoot->addCullCallback(new MyCull);
//m_StateRoot->setUpdateCallback(new MyUpdate);
//m_StateRoot->setEventCallback(new MyEvent);

m_bInitialized = true;

_initialTick = _timer.tick();
_frameTick = _initialTick;

return true;
}



Thank you!

Cheers,
Herman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75053#75053
Robert Osfield
2018-10-09 16:20:49 UTC
Permalink
Hi Herman,
Post by Herman Varma
Yes VTP calls setEventVisitor
m_pOsgViewer->setEventVisitor(NULL);
That's an easy one then, just comment that line out.

The motivation behind the above line is a bit mus-guided as the OSG
keeps track whether a scene graph has an even callbacks and for the
subgraphs that don't contain any it doesn't do any traversal, so if
you don't use event callbacks the event traversal is close to a non
op.

The time you do use an event callback you'll only pay the cost for the
traversal down to the node that has the callback.

If you really do want to switch off the event visitor then setting the
EventVisitor TraversalMask to 0x0 will switch off traversal.

Robert.
Robert Osfield
2018-10-09 16:23:16 UTC
Permalink
Post by Robert Osfield
That's an easy one then, just comment that line out.
The motivation behind the above line is a bit mus-guided as the OSG keeps track whether a scene graph has an even callbacks and for the subgraphs that don't contain any it doesn't do any traversal, so if you don't use event callbacks the event traversal is close to a non op.
The time you do use an event callback you'll only pay the cost for the traversal down to the node that has the callback.
If you really do want to switch off the event visitor then setting the EventVisitor TraversalMask to 0x0 will switch off traversal.
The above features apply along way back, possibly even the OSG-1.x era
so it's safe to have the event visitor attached, so even if you want
to compile against 3.4 and 3.6.x the remove of the
setEventVisitor(NULL); is perfectly safe.

Robert.
Herman Varma
2018-10-09 17:39:45 UTC
Permalink
Hi Robert

I commented out setEventVisitor(NULL) statement.
Thanks to you everything is operating properly with openscenegraph-3.6.3
Now its on to bringing VTP up to spec with wxWidgets.
I fosrsee similar obstacles (sigh!). Hopefully I can iron them out with good people like yourself.

Thanks again

Cheers,
Herman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75057#75057

Continue reading on narkive:
Search results for '[osg-users] porting from osg-3.4.0 to osg-3.6.3' (Questions and Answers)
3
replies
Merchant Navy: Advice on the types of ships to work on?
started 2011-08-16 00:47:11 UTC
boats & boating
Loading...