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