]> git.sesse.net Git - casparcg/commitdiff
* Installed general protection fault handler in more places.
authorHelge Norberg <helge.norberg@svt.se>
Fri, 14 Aug 2015 14:43:33 +0000 (16:43 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Fri, 14 Aug 2015 14:43:33 +0000 (16:43 +0200)
* Catch and log exceptions in all custom boost::threads
* Log the thread name when logging stack traces.
* Fixed bug in AsyncEventServer destructor where "this" will be destroyed when a posted task is executed.

common/log.h
modules/image/consumer/image_consumer.cpp
modules/screen/consumer/screen_consumer.cpp
protocol/osc/client.cpp
protocol/util/AsyncEventServer.cpp
shell/server.cpp

index 023916a739ff89200b05cc22daa06aec329d3477..e9f57110fdfa93cbd9d4a7d0c088acf42c55a5c5 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "os/stack_trace.h"
 #include "utf.h"
+#include "thread_info.h"
 
 #include <boost/log/trivial.hpp>
 #include <boost/log/sources/global_logger_storage.hpp>
@@ -60,28 +61,6 @@ inline std::basic_string<T> replace_nonprintable_copy(std::basic_string<T, std::
 
 void add_file_sink(const std::wstring& folder);
 
-/*template< typename CharT, typename TraitsT >
-inline std::basic_ostream< CharT, TraitsT >& operator<< (
-       std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
-{
-       if(lvl == trace)
-               strm << "trace";
-       else if(lvl == debug)
-               strm << "debug";
-       else if(lvl == info)
-               strm << "info";
-       else if(lvl == warning)
-               strm << "warning";
-       else if(lvl == error)
-               strm << "error";
-       else if(lvl == fatal)
-               strm << "fatal";
-       else
-               strm << static_cast<int>(lvl);
-
-       return strm;
-}*/
-
 typedef boost::log::sources::wseverity_logger_mt<boost::log::trivial::severity_level> caspar_logger;
 
 BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(logger, caspar_logger)
@@ -94,12 +73,12 @@ BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(logger, caspar_logger)
        BOOST_LOG_SEV(::caspar::log::logger::get(), ::boost::log::trivial::lvl)
 
 #define CASPAR_LOG_CALL_STACK()        try{\
-               CASPAR_LOG(info) << L"callstack:\n" << caspar::get_call_stack();\
+               CASPAR_LOG(info) << L"callstack (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\
        }\
        catch(...){}
 
 #define CASPAR_LOG_CURRENT_EXCEPTION() try{\
-               CASPAR_LOG(error)  << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at:\n" << caspar::get_call_stack();\
+               CASPAR_LOG(error)  << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\
        }\
        catch(...){}
        
index ee49fdc003fa1be730fca8d0ae6e0dd38e0bd57d..174b8e5be2fe95ed519c75c4998a6cabe8d09eed 100644 (file)
@@ -27,6 +27,7 @@
 #include <common/utf.h>
 #include <common/array.h>
 #include <common/future.h>
+#include <common/os/general_protection_fault.h>
 
 #include <core/consumer/frame_consumer.h>
 #include <core/video_format.h>
@@ -96,6 +97,8 @@ public:
 
                boost::thread async([frame, filename]
                {
+                       ensure_gpf_handler_installed_for_thread("image-consumer");
+
                        try
                        {
                                auto filename2 = filename;
index 8e563ae4f1c345e4cc17565874f6a65c0ae35150..adc3d5729e2a8e5f1adc0cd471156563ac20e55f 100644 (file)
@@ -35,6 +35,7 @@
 #include <common/future.h>
 #include <common/timer.h>
 #include <common/param.h>
+#include <common/os/general_protection_fault.h>
 
 //#include <windows.h>
 
@@ -299,6 +300,8 @@ public:
 
        void run()
        {
+               ensure_gpf_handler_installed_for_thread("screen-consumer-thread");
+
                try
                {
                        init();
index 12b7a247d1d1bb126da37d730a09c918d9b2afdf..47b55e1c452736aaa412923a61dd0cf33e48df0c 100644 (file)
@@ -31,6 +31,8 @@
 #include <common/except.h>
 #include <common/endian.h>
 #include <common/cache_aligned_vector.h>
+#include <common/os/general_protection_fault.h>
+
 #include <core/monitor/monitor.h>
 
 #include <functional>
@@ -217,6 +219,8 @@ private:
                // http://stackoverflow.com/questions/14993000/the-most-reliable-and-efficient-udp-packet-size
                const int SAFE_DATAGRAM_SIZE = 508;
 
+               ensure_gpf_handler_installed_for_thread("osc-sender-thread");
+
                try
                {
                        is_running_ = true;
index 68d97530ae7787cddcd78ba35637d455d0cc84da..395b156c8e4de7cfcec9ca7595252790c8982836 100644 (file)
@@ -314,12 +314,13 @@ struct AsyncEventServer::implementation
                {
                        CASPAR_LOG_CURRENT_EXCEPTION();
                }
+               auto conns_set = connection_set_;
 
-               service_->post([=]
+               service_->post([conns_set]
                {
-                       auto connections = *connection_set_;
+                       auto connections = *conns_set;
                        for (auto& connection : connections)
-                               connection->stop();                             
+                               connection->stop();
                });
        }
                
index 381d71f8e25bbc0b8fc7a31526c5f6d25d7b95d6..b396063f3d08a774fc09a546047d8dec6e6df725 100644 (file)
@@ -84,11 +84,22 @@ std::shared_ptr<boost::asio::io_service> create_running_io_service()
        // To keep the io_service::run() running although no pending async
        // operations are posted.
        auto work = std::make_shared<boost::asio::io_service::work>(*service);
-       auto thread = std::make_shared<boost::thread>([service]
+       auto weak_work = std::weak_ptr<boost::asio::io_service::work>(work);
+       auto thread = std::make_shared<boost::thread>([service, weak_work]
        {
                ensure_gpf_handler_installed_for_thread("asio-thread");
 
-               service->run();
+               while (weak_work.lock())
+               {
+                       try
+                       {
+                               service->run();
+                       }
+                       catch (...)
+                       {
+                               CASPAR_LOG_CURRENT_EXCEPTION();
+                       }
+               }
        });
 
        return std::shared_ptr<boost::asio::io_service>(
@@ -359,23 +370,30 @@ struct server::impl : boost::noncopyable
        {
                initial_media_info_thread_ = boost::thread([this]
                {
-                       ensure_gpf_handler_installed_for_thread("initial media scan");
-
-                       for (boost::filesystem::wrecursive_directory_iterator iter(env::media_folder()), end; iter != end; ++iter)
+                       try
                        {
-                               if (running_)
-                               {
-                                       if (boost::filesystem::is_regular_file(iter->path()))
-                                               media_info_repo_->get(iter->path().wstring());
-                               }
-                               else
+                               ensure_gpf_handler_installed_for_thread("initial media scan");
+
+                               for (boost::filesystem::wrecursive_directory_iterator iter(env::media_folder()), end; iter != end; ++iter)
                                {
-                                       CASPAR_LOG(info) << L"Initial media information retrieval aborted.";
-                                       return;
+                                       if (running_)
+                                       {
+                                               if (boost::filesystem::is_regular_file(iter->path()))
+                                                       media_info_repo_->get(iter->path().wstring());
+                                       }
+                                       else
+                                       {
+                                               CASPAR_LOG(info) << L"Initial media information retrieval aborted.";
+                                               return;
+                                       }
                                }
-                       }
 
-                       CASPAR_LOG(info) << L"Initial media information retrieval finished.";
+                               CASPAR_LOG(info) << L"Initial media information retrieval finished.";
+                       }
+                       catch (...)
+                       {
+                               CASPAR_LOG_CURRENT_EXCEPTION();
+                       }
                });
        }
 };