-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
118 lines (91 loc) · 3.32 KB
/
main.cpp
File metadata and controls
118 lines (91 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "argparse/argparse.hpp"
#include <spdlog/spdlog.h>
#include <filesystem>
#include "xmotion/core/boot/i_boot.h"
#include "xmotion/imgui/imgui_boot.h"
#include "xmotion/fbgtk/file_boot.h"
#define CL_TARGET_OPENCL_VERSION 300
namespace xm::error {
#ifdef _WIN32
#include <windows.h>
#include <DbgHelp.h>
#pragma comment(lib, "Dbghelp.lib")
void printStackTrace() {
// Honestly I have no idea if this would work
HANDLE process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
void* stack[100];
unsigned short frames = CaptureStackBackTrace(0, 100, stack, NULL);
SYMBOL_INFO* symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1);
symbol->MaxNameLen = 255;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
for (unsigned int i = 0; i < frames; i++) {
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol);
std::cerr << frames - i - 1 << ": " << symbol->Name << " at 0x" << std::hex << symbol->Address << std::dec << std::endl;
}
free(symbol);
}
#else
#include <execinfo.h>
void printStackTrace() {
void *array[10];
// get void*'s for all entries on the stack
const int size = backtrace(array, 10);
// print out all the frames
char **messages = backtrace_symbols(array, size);
for (size_t i = 0; i < size; ++i) { // Using size_t for loop counter
std::cerr << messages[i] << std::endl;
}
free(messages);
}
}
#endif
int main(int argc, char **argv) {
argparse::ArgumentParser program("xmotion", "0.0.1");
program.add_description(R"desc(
To list available capture devices on linux you can use:
[ $ v4l2-ctl --list-devices ]
For proper configuration first check your camera allowed properties
[ $ v4l2-ctl -d \"/dev/video${ID}\" --list-formats-ext ]
)desc");
program.add_argument("-p", "--project")
.default_value(std::string(std::filesystem::current_path().string()))
.help("Project root directory");
program.add_argument("-g", "--graphic")
.help("Graphic mode")
.flag();
program.add_argument("-v", "--verbose")
.help("Increase output verbosity")
.flag();
try {
program.parse_args(argc, argv);
} catch (const std::runtime_error &err) {
std::cout << err.what() << '\n';
std::cout << program;
return 1;
}
if (program.get<bool>("--verbose")) {
spdlog::set_level(spdlog::level::debug);
} else {
spdlog::set_level(spdlog::level::info);
}
std::unique_ptr<xm::Boot> director;
if (program.get<bool>("--graphic")) {
director = std::make_unique<xm::IMGuiBoot>();
} else {
director = std::make_unique<xm::FileBoot>();
}
try {
director->open_project(program.get<std::string>("--project").c_str());
return director->boot(argc, argv);
} catch (std::exception &e) {
std::cerr << "Unexpected Exception: " << e.what() << '\n';
xm::error::printStackTrace();
return 1;
} catch (...) {
std::cerr << "Debug Report: An exception occurred" << '\n';
xm::error::printStackTrace();
return 1;
}
return 0;
}