# null in this-\>GetDefaultRenderer() in virtual void OnRightButtonDown()

**URL:** https://discourse.vtk.org/t/null-in-this-getdefaultrenderer-in-virtual-void-onrightbuttondown/352
**Category:** Support
**Created:** [March 1, 2019, 10:27am UTC](https://discourse.vtk.org/t/null-in-this-getdefaultrenderer-in-virtual-void-onrightbuttondown/352 "2019-03-01T10:27:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [March 1, 2019, 10:27am UTC](https://discourse.vtk.org/t/null-in-this-getdefaultrenderer-in-virtual-void-onrightbuttondown/352/1 "2019-03-01T10:27:25Z")

</div>

Dear all,

I have a doubt of programming. I am trying the examples of picking points from the mouse.

I see in the virtual function of the mouse (OnRightButtonDown()) when i want to get the renderer,  
it returns null.

If i do this this-\>GetDefaultRenderer() i get a an error. So the pointer do not add the renderer info

By now, what i did was a global variable of the mainrenderer and it is working but i want to keep my code clean and i would like to understand why i cannot get this info from this

this-\>GetDefaultRenderer()

However

int\* pos = this-\>GetInteractor()-\>GetEventPosition();

this works

it is only the renderer.

I hope you can help me so i can remove this global variable. To continue programming it is fine but i wold like to keep the code as clean as possible.

Thanks

I attach the code i want to replace the global\_renderer with this-\>GetDefaultRenderer().

Thanks

class customMouseInteractorStyle : public vtkInteractorStyleTrackballCamera  
{  
public:  
static customMouseInteractorStyle\* New();  
vtkTypeMacro(customMouseInteractorStyle, vtkInteractorStyleTrackballCamera);

```
	virtual void OnRightButtonDown()
	{
		// Get the location of the click (in window coordinates)
		int* pos = this->GetInteractor()->GetEventPosition();

		vtkSmartPointer<vtkCellPicker> picker =
			vtkSmartPointer<vtkCellPicker>::New();
		picker->SetTolerance(0.0005);

		//this->GetDefaultRenderer()->Clear();

		// Pick from this location.
		picker->Pick(pos[0], pos[1], 0, global_renderer);

		double* worldPosition = picker->GetPickPosition();
		std::cout << "Cell id is: " << picker->GetCellId() << std::endl;

		if (picker->GetCellId() != -1)
		{

			std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1]
				<< " " << worldPosition[2] << endl;
		}

		// Forward events
		vtkInteractorStyleTrackballCamera::OnRightButtonDown();
		
	}

};
```

---

<div class="post-metadata">

### Author: ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)
#### Post date: [March 1, 2019, 2:12pm UTC](https://discourse.vtk.org/t/null-in-this-getdefaultrenderer-in-virtual-void-onrightbuttondown/352/2 "2019-03-01T14:12:39Z")

</div>

When you instantiate your custom style, make sure to set the default renderer on it using `vtkInteractorStyle::SetDefaultRenderer()`

Something like:

```cpp
vtkNew<customMouseInteractorStyle> style;
style->SetDefaultRenderer(ren);

```
