Kaydet (Commit) fd6263e3 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst cd103a88
......@@ -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;
......
......@@ -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;
......
......@@ -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 );
......
......@@ -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();
......
......@@ -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
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment