Fix crash if camera is not set
This commit is contained in:
@@ -12,6 +12,9 @@ namespace OpenVulkano::Scene
|
||||
{
|
||||
void SceneIntersectionTestController::Tick()
|
||||
{
|
||||
if (!m_camera) [[unlikely]] { return; }
|
||||
const auto scene = m_camera->GetScene();
|
||||
if (!scene) return;
|
||||
Input::InputManager* input = Input::InputManager::GetInstance();
|
||||
if (input->GetButtonDown(m_actionClick))
|
||||
{
|
||||
@@ -19,7 +22,6 @@ namespace OpenVulkano::Scene
|
||||
const float y = input->GetAxis(m_actionClickY);
|
||||
const Ray ray = m_camera->CastRay(Math::Vector2i(x, y));
|
||||
const auto& camPos = m_camera->GetPosition();
|
||||
const auto scene = m_camera->GetScene();
|
||||
std::optional<DrawableRayHit> res;
|
||||
for (Drawable* d : scene->rayHittableDrawables)
|
||||
{
|
||||
|
||||
@@ -10,18 +10,25 @@
|
||||
#include "Scene/Ray.hpp"
|
||||
#include "Input/InputAction.hpp"
|
||||
#include "Scene/Camera.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
class SceneIntersectionTestController : public ITickable
|
||||
{
|
||||
public:
|
||||
SceneIntersectionTestController() = default;
|
||||
SceneIntersectionTestController(): m_camera(nullptr_t) = default;
|
||||
|
||||
SceneIntersectionTestController(Camera* camera) : m_camera(camera) {}
|
||||
|
||||
void SetCamera(Camera* camera) { m_camera = camera; }
|
||||
|
||||
[[nodiscard]] Camera* GetCamera() const { return m_camera; }
|
||||
|
||||
void Tick() override;
|
||||
|
||||
void SetDefaultKeybindings();
|
||||
|
||||
Event<DrawableRayHit> OnHit;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user