From c17d937ee5d35c1edaccf10abef47324a08b3c55 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sat, 17 Feb 2018 14:54:43 -0800 Subject: [PATCH] Fixed the most common crash on exit, still one more hiding and crashing in libc --- include/Application.h | 3 ++- include/CLCaster.h | 2 +- include/Camera.h | 2 +- include/Input.h | 2 +- include/LightController.h | 2 +- include/LightHandle.h | 2 +- include/Pub_Sub.h | 20 +++++++++++++++++++- src/Application.cpp | 5 +++++ src/CLCaster.cpp | 2 +- src/Camera.cpp | 2 +- src/LightController.cpp | 2 +- src/LightHandle.cpp | 2 +- src/Pub_Sub.cpp | 4 ++-- 13 files changed, 37 insertions(+), 13 deletions(-) diff --git a/include/Application.h b/include/Application.h index 69688ac..4f24e0d 100644 --- a/include/Application.h +++ b/include/Application.h @@ -40,7 +40,8 @@ class CLCaster; class Application { -public: +public: + // static const int WINDOW_X = 1366; // static const int WINDOW_Y = 768; static const int WINDOW_X = 1920; diff --git a/include/CLCaster.h b/include/CLCaster.h index 82cac44..b1db061 100644 --- a/include/CLCaster.h +++ b/include/CLCaster.h @@ -168,7 +168,7 @@ public: virtual void render_gui() override; virtual void update_gui() override; - virtual void recieve_event(VrEventPublisher* publisher, std::unique_ptr event) override; + virtual void event_handler(VrEventPublisher *publisher, std::unique_ptr event) override; // ================================ diff --git a/include/Camera.h b/include/Camera.h index f70f5c5..897406e 100644 --- a/include/Camera.h +++ b/include/Camera.h @@ -57,7 +57,7 @@ public: void setSpeed(float speed); float getSpeed(); - void recieve_event(VrEventPublisher* publisher, std::unique_ptr event) override; + void event_handler(VrEventPublisher *publisher, std::unique_ptr event) override; virtual void render_gui() override; diff --git a/include/Input.h b/include/Input.h index e21d733..6a266f8 100644 --- a/include/Input.h +++ b/include/Input.h @@ -63,7 +63,7 @@ class WindowHandler : public VrEventSubscriber { public: WindowHandler(sf::RenderWindow *window) : window_ref(window) { }; - virtual void recieve_event(VrEventPublisher* publisher, std::unique_ptr(event)) override { + virtual void event_handler(VrEventPublisher *publisher, std::unique_ptr(event)) override { if (event.get()->type == vr::Event::Closed) { window_ref->close(); diff --git a/include/LightController.h b/include/LightController.h index c66bb6c..218c7a8 100644 --- a/include/LightController.h +++ b/include/LightController.h @@ -87,7 +87,7 @@ public: void remove_light(unsigned int light_index); - void recieve_event(VrEventPublisher* publisher, std::unique_ptr event) override; + void event_handler(VrEventPublisher *publisher, std::unique_ptr event) override; private: diff --git a/include/LightHandle.h b/include/LightHandle.h index c49fe70..263d3b0 100644 --- a/include/LightHandle.h +++ b/include/LightHandle.h @@ -33,7 +33,7 @@ public: void set_rgbi(sf::Vector4f rgbi); - virtual void recieve_event(VrEventPublisher* publisher, std::unique_ptr event) override; + virtual void event_handler(VrEventPublisher *publisher, std::unique_ptr event) override; void update(double delta_time); diff --git a/include/Pub_Sub.h b/include/Pub_Sub.h index 7b486c9..98f5ba6 100644 --- a/include/Pub_Sub.h +++ b/include/Pub_Sub.h @@ -7,10 +7,28 @@ class VrEventPublisher; + + +/** + * + * VrEventSubscriber + * + * When inherited, the user must impliment a + * + * + * + * + * + * + * + */ + + + class VrEventSubscriber { public: virtual ~VrEventSubscriber(); - virtual void recieve_event(VrEventPublisher* publisher, std::unique_ptr event) = 0; + virtual void event_handler(VrEventPublisher *publisher, std::unique_ptr event) = 0; void subscribe_to_publisher(VrEventPublisher* publisher, vr::Event::EventType type); void subscribe_to_publisher(VrEventPublisher* publisher, std::vector type); void unsubscribe(VrEventPublisher* publisher, vr::Event::EventType type); diff --git a/src/Application.cpp b/src/Application.cpp index 2e869e9..0f0e129 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -18,6 +18,11 @@ Application::Application() { Application::~Application() { + if (window.unique()) + window.reset(); + else { + Logger::log("Can't release window, shared_ptr coun : " + window.use_count(), Logger::LogLevel::WARN); + } //light_handle->~LightHandle(); //light_controller->~LightController(); } diff --git a/src/CLCaster.cpp b/src/CLCaster.cpp index c8146da..c4e7bda 100644 --- a/src/CLCaster.cpp +++ b/src/CLCaster.cpp @@ -370,7 +370,7 @@ void CLCaster::update_gui() { } -void CLCaster::recieve_event(VrEventPublisher* publisher, std::unique_ptr event) { +void CLCaster::event_handler(VrEventPublisher *publisher, std::unique_ptr event) { if (event->type == vr::Event::KeyPressed) { diff --git a/src/Camera.cpp b/src/Camera.cpp index 1f3dcf5..1e7ddef 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -94,7 +94,7 @@ int Camera::update(double delta_time) { return 1; } -void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr event) { +void Camera::event_handler(VrEventPublisher *publisher, std::unique_ptr event) { if (event->type == vr::Event::KeyHeld) { diff --git a/src/LightController.cpp b/src/LightController.cpp index b6651f4..c8e5686 100644 --- a/src/LightController.cpp +++ b/src/LightController.cpp @@ -36,7 +36,7 @@ void LightController::remove_light(unsigned int light_index) { } -void LightController::recieve_event(VrEventPublisher* publisher, std::unique_ptr event) { +void LightController::event_handler(VrEventPublisher *publisher, std::unique_ptr event) { if (event->type == vr::Event::KeyHeld) {} else if (event->type == vr::Event::KeyPressed) {} diff --git a/src/LightHandle.cpp b/src/LightHandle.cpp index 8f5e301..9df8ce4 100644 --- a/src/LightHandle.cpp +++ b/src/LightHandle.cpp @@ -68,7 +68,7 @@ void LightHandle::set_rgbi(sf::Vector4f rgbi) data_reference->rgbi = rgbi; } -void LightHandle::recieve_event(VrEventPublisher* publisher, std::unique_ptr event) +void LightHandle::event_handler(VrEventPublisher *publisher, std::unique_ptr event) { if (event->type == vr::Event::JoystickMoved) { diff --git a/src/Pub_Sub.cpp b/src/Pub_Sub.cpp index a2c621f..4cd5dd3 100644 --- a/src/Pub_Sub.cpp +++ b/src/Pub_Sub.cpp @@ -74,10 +74,10 @@ void VrEventPublisher::notify_subscribers(std::unique_ptr event) { //std::vector *event_type_bucket = &subscribers[event->type]; // Send them the event - // Each and every event that is received in the recieve_event function + // Each and every event that is received in the event_handler function // will be a unique ptr solely owned by that function for (auto s : subscribers[event->type]) { - s->recieve_event(this, event->clone()); + s->event_handler(this, event->clone()); } }