From fd6263e37641657f8bf81f42e72c7074263d277d Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 6 Jan 2016 13:22:26 +0100 Subject: 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 --- svx/source/customshapes/EnhancedCustomShape3d.cxx | 2 +- svx/source/dialog/dlgctl3d.cxx | 4 ++-- svx/source/engine3d/scene3d.cxx | 19 +++++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) (limited to 'svx/source') 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(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 { -- cgit v1.2.3