Skip to content

Commit

Permalink
fix crash when creating a second view and closing the first view whil…
Browse files Browse the repository at this point in the history
…e the dragger task panel is open
  • Loading branch information
wwmayer committed Oct 9, 2016
1 parent f712e1c commit 776c0bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
39 changes: 23 additions & 16 deletions src/Gui/SoFCCSysDragger.cpp
Expand Up @@ -910,7 +910,6 @@ void SoFCCSysDragger::setUpAutoScale(SoCamera *cameraIn)
//note: sofieldsensor checks if the current sensor is already attached
//and takes appropriate action. So it is safe to attach to a field without
//checking current attachment state.
camera = cameraIn;
if (cameraIn->getTypeId() == SoOrthographicCamera::getClassTypeId())
{
SoOrthographicCamera *localCamera = dynamic_cast<SoOrthographicCamera *>(cameraIn);
Expand Down Expand Up @@ -943,28 +942,36 @@ void SoFCCSysDragger::cameraCB(void *data, SoSensor *)
void SoFCCSysDragger::idleCB(void *data, SoSensor *)
{
SoFCCSysDragger *sudoThis = reinterpret_cast<SoFCCSysDragger *>(data);
assert(sudoThis->camera);

SbMatrix localToWorld = sudoThis->getLocalToWorldMatrix();
SbVec3f origin;
localToWorld.multVecMatrix(SbVec3f(0.0, 0.0, 0.0), origin);

SbViewVolume viewVolume = sudoThis->camera->getViewVolume();
float radius = sudoThis->draggerSize.getValue() / 2.0;
float localScale = viewVolume.getWorldToScreenScale(origin, radius);
SbVec3f scaleVector(localScale, localScale, localScale);
SoScale *localScaleNode = SO_GET_ANY_PART(sudoThis, "scaleNode", SoScale);
localScaleNode->scaleFactor.setValue(scaleVector);
sudoThis->autoScaleResult.setValue(localScale);
SoField* field = sudoThis->cameraSensor.getAttachedField();
if (field)
{
SoCamera* camera = static_cast<SoCamera*>(field->getContainer());
SbMatrix localToWorld = sudoThis->getLocalToWorldMatrix();
SbVec3f origin;
localToWorld.multVecMatrix(SbVec3f(0.0, 0.0, 0.0), origin);

SbViewVolume viewVolume = camera->getViewVolume();
float radius = sudoThis->draggerSize.getValue() / 2.0;
float localScale = viewVolume.getWorldToScreenScale(origin, radius);
SbVec3f scaleVector(localScale, localScale, localScale);
SoScale *localScaleNode = SO_GET_ANY_PART(sudoThis, "scaleNode", SoScale);
localScaleNode->scaleFactor.setValue(scaleVector);
sudoThis->autoScaleResult.setValue(localScale);
}
}

void SoFCCSysDragger::finishDragCB(void *data, SoDragger *)
{
SoFCCSysDragger *sudoThis = reinterpret_cast<SoFCCSysDragger *>(data);

if (sudoThis->camera)
// note: when creating a second view of the document and then closing
// the first viewer it deletes the camera. However, the attached field
// of the cameraSensor will be detached automatically.
SoField* field = sudoThis->cameraSensor.getAttachedField();
if (field)
{
if (sudoThis->camera->getTypeId() == SoPerspectiveCamera::getClassTypeId())
SoCamera* camera = static_cast<SoCamera*>(field->getContainer());
if (camera->getTypeId() == SoPerspectiveCamera::getClassTypeId())
cameraCB(sudoThis, nullptr);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Gui/SoFCCSysDragger.h
Expand Up @@ -207,7 +207,6 @@ class GuiExport SoFCCSysDragger : public SoDragger

SoIdleSensor idleSensor; //!< might be overkill, but want to make sure of performance.
void setUpAutoScale(SoCamera *cameraIn); //!< used to setup the auto scaling of dragger.
SoCamera *camera = nullptr; //!< don't assign directly! use setUpAutoScale.

//! @name Visibility Functions
//@{
Expand Down

0 comments on commit 776c0bd

Please sign in to comment.