summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-01-06 13:22:26 +0100
committerStephan Bergmann <sbergman@redhat.com>2016-01-06 13:22:26 +0100
commitfd6263e37641657f8bf81f42e72c7074263d277d (patch)
treee8378e9e8d7890499c7097daf324e289039469ac
parentcd103a888b8149aca66c7a93b91f8f7c2f1dbe31 (diff)
Make E3dScene3D::GetCamera return non-reference
I stumbled over this when Valgrind'ing CppunitTest_sd_filters_test somewhat erroneously reported Source and destination overlap in memcpy(0x2fde4af8, 0x2fde4af8, 96) for aCamera = rNewCamera; in E3dScene::SetCamera (svx/source/engine3d/scene3d.cxx), where the compiler chose to use memcpy in the implicit definition of the Viewport3D (being a base class of Camera3D) copy assignment operator, and the call pattern of Get/SetCamera in EnhancedCustomShape3d::Create3DObject (svx/source/customshapes/EnhancedCustomShape3d.cxx) causes that assignment to be a self-assignment. Upon closer inspection, some calls of GetCamera already create a copy from the returned reference, while others modified the returned reference, but then would also always call SetCamera on it. An alternative to the given change would have been to instead change SetCamera(Camera3D&) to UpdateCamera() and require all call sites of GetCamera/UpdateCamera to modify the reference returned from GetCamera, but it looks safer overall to go this way. Change-Id: I578e72db57630dca1b09124a3b11d177005b797d
-rw-r--r--include/svx/scene3d.hxx2
-rw-r--r--sd/source/ui/func/fucon3d.cxx2
-rw-r--r--svx/source/customshapes/EnhancedCustomShape3d.cxx2
-rw-r--r--svx/source/dialog/dlgctl3d.cxx4
-rw-r--r--svx/source/engine3d/scene3d.cxx19
5 files changed, 12 insertions, 17 deletions
diff --git a/include/svx/scene3d.hxx b/include/svx/scene3d.hxx
index f8642e02b540..70d77e8373f8 100644
--- a/include/svx/scene3d.hxx
+++ b/include/svx/scene3d.hxx
@@ -126,7 +126,7 @@ public:
virtual E3dScene* GetScene() const override;
void SetCamera(const Camera3D& rNewCamera);
- const Camera3D& GetCamera() const { return aCamera; }
+ Camera3D GetCamera() const { return aCamera; }
void removeAllNonSelectedObjects();
virtual E3dScene* Clone() const override;
diff --git a/sd/source/ui/func/fucon3d.cxx b/sd/source/ui/func/fucon3d.cxx
index 0c27ad0381c3..702d1bd0a106 100644
--- a/sd/source/ui/func/fucon3d.cxx
+++ b/sd/source/ui/func/fucon3d.cxx
@@ -238,7 +238,7 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
void FuConstruct3dObject::ImpPrepareBasic3DShape(E3dCompoundObject* p3DObj, E3dScene *pScene)
{
- Camera3D &aCamera = (Camera3D&) pScene->GetCamera ();
+ Camera3D aCamera = pScene->GetCamera ();
// get transformed BoundVolume of the new object
basegfx::B3DRange aBoundVol;
diff --git a/svx/source/customshapes/EnhancedCustomShape3d.cxx b/svx/source/customshapes/EnhancedCustomShape3d.cxx
index 7e2b45ee057a..1f802b8bc49e 100644
--- a/svx/source/customshapes/EnhancedCustomShape3d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape3d.cxx
@@ -574,7 +574,7 @@ SdrObject* EnhancedCustomShape3d::Create3DObject( const SdrObject* pShape2d, con
pRet = pScene;
// Camera settings, Perspective ...
- Camera3D& rCamera = (Camera3D&)pScene->GetCamera();
+ Camera3D rCamera = pScene->GetCamera();
const basegfx::B3DRange& rVolume = pScene->GetBoundVolume();
pScene->NbcSetSnapRect( aSnapRect );
diff --git a/svx/source/dialog/dlgctl3d.cxx b/svx/source/dialog/dlgctl3d.cxx
index 2dbd53e6f72b..482a89d794ba 100644
--- a/svx/source/dialog/dlgctl3d.cxx
+++ b/svx/source/dialog/dlgctl3d.cxx
@@ -103,7 +103,7 @@ void Svx3DPreviewControl::Construct()
SetObjectType(SvxPreviewObjectType::SPHERE);
// camera and perspective
- Camera3D& rCamera = (Camera3D&) mpScene->GetCamera();
+ Camera3D rCamera = mpScene->GetCamera();
const basegfx::B3DRange& rVolume = mpScene->GetBoundVolume();
double fW = rVolume.getWidth();
double fH = rVolume.getHeight();
@@ -341,7 +341,7 @@ void Svx3DLightControl::Construct2()
{
// change camera settings
- Camera3D& rCamera = (Camera3D&) mpScene->GetCamera();
+ Camera3D rCamera = mpScene->GetCamera();
const basegfx::B3DRange& rVolume = mpScene->GetBoundVolume();
double fW = rVolume.getWidth();
double fH = rVolume.getHeight();
diff --git a/svx/source/engine3d/scene3d.cxx b/svx/source/engine3d/scene3d.cxx
index 911aca6e1820..7ca48718a07d 100644
--- a/svx/source/engine3d/scene3d.cxx
+++ b/svx/source/engine3d/scene3d.cxx
@@ -330,31 +330,27 @@ void E3dScene::NbcResize(const Point& rRef, const Fraction& rXFact,
void E3dScene::SetCamera(const Camera3D& rNewCamera)
{
- // Set old camera
aCamera = rNewCamera;
static_cast<sdr::properties::E3dSceneProperties&>(GetProperties()).SetSceneItemsFromCamera();
SetRectsDirty();
- // Fill new camera from old
- Camera3D& rCam = (Camera3D&)GetCamera();
-
// Turn off ratio
- if(rCam.GetAspectMapping() == AS_NO_MAPPING)
+ if(aCamera.GetAspectMapping() == AS_NO_MAPPING)
GetCameraSet().SetRatio(0.0);
// Set Imaging geometry
- basegfx::B3DPoint aVRP(rCam.GetViewPoint());
- basegfx::B3DVector aVPN(aVRP - rCam.GetVRP());
- basegfx::B3DVector aVUV(rCam.GetVUV());
+ basegfx::B3DPoint aVRP(aCamera.GetViewPoint());
+ basegfx::B3DVector aVPN(aVRP - aCamera.GetVRP());
+ basegfx::B3DVector aVUV(aCamera.GetVUV());
// use SetViewportValues() to set VRP, VPN and VUV as vectors, too.
// Else these values would not be exported/imported correctly.
GetCameraSet().SetViewportValues(aVRP, aVPN, aVUV);
// Set perspective
- GetCameraSet().SetPerspective(rCam.GetProjection() == PR_PERSPECTIVE);
- GetCameraSet().SetViewportRectangle((Rectangle&)rCam.GetDeviceWindow());
+ GetCameraSet().SetPerspective(aCamera.GetProjection() == PR_PERSPECTIVE);
+ GetCameraSet().SetViewportRectangle((Rectangle&)aCamera.GetDeviceWindow());
ImpCleanup3DDepthMapper();
}
@@ -646,8 +642,7 @@ void E3dScene::RecalcSnapRect()
{
// The Scene is used as a 2D-Objekt, take the SnapRect from the
// 2D Display settings
- Camera3D& rCam = (Camera3D&)pScene->GetCamera();
- maSnapRect = rCam.GetDeviceWindow();
+ maSnapRect = pScene->aCamera.GetDeviceWindow();
}
else
{