# Error with StyleInteractor

**URL:** https://discourse.vtk.org/t/error-with-styleinteractor/9640
**Category:** Support
**Tags:** python
**Created:** [October 18, 2022, 4:21pm UTC](https://discourse.vtk.org/t/error-with-styleinteractor/9640 "2022-10-18T16:21:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [October 18, 2022, 4:21pm UTC](https://discourse.vtk.org/t/error-with-styleinteractor/9640/1 "2022-10-18T16:21:35Z")

</div>

I have the following code

```auto
class MyInteractorStyle(vtkInteractorStyleTerrain):
    
    def __init__ (self, renderer):
        
        self.SetCurrentRenderer(renderer)
        self.AddObserver("MouseMoveEvent", self.mouse_move_event)

    
    def mouse_move_event(self, obj, event):
       
        # Get the interactor
        iren = self.GetInteractor()
        if iren is None: return

        dx = iren.GetEventPosition()[0] - iren.GetLastEventPosition()[0];
        dy = iren.GetEventPosition()[1] - iren.GetLastEventPosition()[1];

        camera = self.GetCurrentRenderer().GetActiveCamera()
        camera.SetRoll(0)
        screenSize = iren.GetRenderWindow().GetSize()

        # Yaw changes in a negative direction but the pitch is correct
        camera.Yaw(-float(dx) / float(screenSize[0]) * 360 * 2.0);
        camera.Pitch(float(dy) / float(screenSize[1]) * 180 / 2.0);

        # Update the clipping range of the camera
        self.GetCurrentRenderer().ResetCameraClippingRange()
        
        # render
        self.GetCurrentRenderer().GetRenderWindow().Render()
        return

```

However everytime I move the mouse, I get the following error:

Input In [4], in MyInteractorStyle.mouse\_move\_event(self, obj, event)

—\> 25 camera = self.GetCurrentRenderer().GetActiveCamera()

AttributeError: ‘NoneType’ object has no attribute ‘GetActiveCamera’

I pass a renderer whenever I initialize an instance of MyInteractorStyle

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 20, 2022, 9:40pm UTC](https://discourse.vtk.org/t/error-with-styleinteractor/9640/2 "2022-10-20T21:40:41Z")

</div>

Hello,

Calling setter methods from inside the constructor, though not illegal, should be considered an unsafe operation. It’s best to set the renderer elsewhere after instantiating your `MyInteractorStyle` object.

take care,

Paulo

---

<div class="post-metadata">

### Author: ![llobera](https://discourse.vtk.org/user_avatar/discourse.vtk.org/llobera/32/5540_2.png) [@llobera](https://discourse.vtk.org/u/llobera)
#### Post date: [October 21, 2022, 8:23am UTC](https://discourse.vtk.org/t/error-with-styleinteractor/9640/3 "2022-10-21T08:23:03Z")

</div>

Thanks for the clarification, Paulo.

I was just following an example I found (pretty much all that is available given the sparcity of information available).

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 21, 2022, 1:20pm UTC](https://discourse.vtk.org/t/error-with-styleinteractor/9640/4 "2022-10-21T13:20:13Z")

</div>

Hi,

Not all code snippets out there have good practices. During constructor execution, one should consider the object is incomplete, hence the name: constructor: it means that the object is under construction. Thus, changing the state of the object in the constructor shouldn’t be considered safe. You can perfectly set the renderer after instantiating the object.

regards,

Paulo
