ambrosiogabe / MathAnimation

A simple C++/OpenGL application to create quick and dirty mathematically accurate animations
982 stars 49 forks source link

Add Linux support #47

Closed Toby222 closed 1 year ago

Toby222 commented 1 year ago

Once finished, this PR should allow MathAnimation to run on Linux.

3top1a commented 1 year ago

Just a small tidbit, the build script does not check whether premake is installed or not.

arf20 commented 1 year ago

I get an error trying to build this in gcc 10 in Debian 11 with ffmpeg 4.3.5:

/home/arf20/source/MathAnimation/Animations/src/video/Encoder.cpp:70:77: error: invalid conversion from ‘const AVOutputFormat*’ to ‘AVOutputFormat*’ [-fpermissive]
   70 |    int err = avformat_alloc_output_context2(&output->formatContext, output->outputFormat, nullptr, outputFilename);
      |                                                                     ~~~~~~~~^~~~~~~~~~~~
      |                                                                             |
      |                                                                             const AVOutputFormat*

avformat_alloc_output_context2 expects non-const there, version mismatch?

Toby222 commented 1 year ago

I get an error trying to build this in gcc 10 in Debian 11 with ffmpeg 4.3.5:

/home/arf20/source/MathAnimation/Animations/src/video/Encoder.cpp:70:77: error: invalid conversion from ‘const AVOutputFormat*’ to ‘AVOutputFormat*’ [-fpermissive]
   70 |    int err = avformat_alloc_output_context2(&output->formatContext, output->outputFormat, nullptr, outputFilename);
      |                                                                     ~~~~~~~~^~~~~~~~~~~~
      |                                                                             |
      |                                                                             const AVOutputFormat*

avformat_alloc_output_context2 expects non-const there, version mismatch?

The ffmpeg in the submodule is supposed to be of a version 4.4.git, in which it does in fact expect a const AVOutputFormat*

The function signature in question

Which is also what we pass (from incloude/video/Encoder.h:31) The data type of the passed argument

mywave82 commented 1 year ago

The function signature in question

Which is also what we pass (from include/video/Encoder.h:31) The data type of the passed argument

Animations/include/video/Encoder.h defines "struct AVCodecContext" as an anonymous C++ scoped structure, while it probably should have been C scoped, or included #include

ambrosiogabe commented 1 year ago

Hey @mywave82 . Like you said this can be fixed by adding extern "C" around the forward declarations, I didn't realize they were C structures at the time. I like to keep header files as light as possible and only include "core.h" unless it's a special case to keep re-compile times as low as possible :)

3top1a commented 1 year ago

Another little tidbit: It crashes if you don't have the cuda toolbox installed (nsight is missing). I don't know if it's in the windows version, but there should be a check for it.

Toby222 commented 1 year ago

Another little tidbit: It crashes if you don't have the cuda toolbox installed (nsight is missing). I don't know if it's in the windows version, but there should be a check for it.

Can't replicate on account of me not having an NVIDIA GPU 😅

Do you have any more details on that?

3top1a commented 1 year ago

Without CUDA Toolbox, MathAnim crashes with the following error:

/tmp/MathAnimation/Animations/src/parsers/Grammar.cpp (line 50) Warning:
[2023-01-19 06:41:01]: Invalid capture list. Capture '0' does not contain a 'name' key.
/tmp/MathAnimation/Animations/src/parsers/Grammar.cpp (line 50) Warning:
[2023-01-19 06:41:01]: Invalid capture list. Capture '1' does not contain a 'name' key.
/tmp/MathAnimation/Animations/src/parsers/Grammar.cpp (line 50) Warning:
[2023-01-19 06:41:01]: Invalid capture list. Capture '15' does not contain a 'name'
key.
/tmp/MathAnimation/Animations/src/parsers/Grammar.cpp (line 50) Warning:
[2023-01-19 06:41:01]: Invalid capture list. Capture '7' does not contain a 'name' key.
/tmp/MathAnimation/Animations/src/parsers/Grammar.cpp (line 50) Warning:
[2023-01-19 06:41:01]: Invalid capture list. Capture '2' does not contain a 'name' key.
/tmp/MathAnimation/Animations/src/parsers/SyntaxHighlighter.cpp (line 109) Info:
[2023-01-19 06:41:01]: Successfully imported default languages and themes for syntax highlighters.
terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error'
  what():  filesystem error: directory iterator cannot open directory: No such file
or directory [/opt/cuda/nsight_compute]
zsh: IOT instruction (core dumped)  ./MathAnimations

Here's the backtrace from gdb:

0x00007ffff40a164c in ?? () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff40a164c in  () at /usr/lib/libc.so.6
#1  0x00007ffff4051958 in raise () at /usr/lib/libc.so.6
#2  0x00007ffff403b53d in abort () at /usr/lib/libc.so.6
#3  0x00007ffff4299833 in __gnu_cxx::__verbose_terminate_handler() () at /usr/src/debug/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#4  0x00007ffff42a5cfc in __cxxabiv1::__terminate(void (*)()) (handler=<optimized out>) at /usr/src/debug/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#5  0x00007ffff42a5d69 in std::terminate() () at /usr/src/debug/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#6  0x00007ffff42a5fcd in __cxxabiv1::__cxa_throw(void*, std::type_info*, void (*)(void*))

     (obj=<optimized out>, tinfo=0x7ffff442f818 <typeinfo for std::filesystem::__cxx11::filesystem_error>, dest=0x7ffff4388340 <std::filesystem::__cxx11::filesystem_error::~filesystem_error()>) at /usr/src/debug/gcc/libstdc++-v3/libsupc++/eh_throw.cc:98
#7  0x00007ffff429d4dc in std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path const&, std::filesystem::directory_options, std::error_code*)
    (this=this@entry=0x7fffffffdb00, p=filesystem::path "/opt/cuda/nsight_compute" = {...}, options=options@entry=std::filesystem::directory_options::none, ecptr=ecptr@entry=0x0) at /usr/src/debug/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/new_allocator.h:90
#8  0x0000555555b964e1 in std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path const&)
    (__p=filesystem::path "/opt/cuda/nsight_compute" = {...}, this=0x7fffffffdb00, this=<optimized out>, __p=<optimized out>)
    at /usr/include/c++/12.2.0/bits/fs_dir.h:387
#9  MathAnim::Platform::getProgramInstallDir(char const*, char*, unsigned long) [clone .constprop.0]
    (bufferLength=520, buffer=<optimized out>, programDisplayName=0x555555733f13 "miktex") at /tmp/MathAnimation/Animations/src/platform/PlatformLinux.cpp:130
#10 0x0000555555b39436 in MathAnim::LaTexLayer::init() () at /tmp/MathAnimation/Animations/src/latex/LaTexLayer.cpp:82
#11 MathAnim::Application::init(char const*) (projectFile=<optimized out>) at /tmp/MathAnimation/Animations/src/core/Application.cpp:121
#12 0x0000555555b53b5b in main() () at /usr/include/c++/12.2.0/bits/basic_string.h:233

Locals in frame 9:

(gdb)  info locals
directory_entry = <optimized out>
__for_range = <optimized out>
__for_begin = {_M_dir = {<std::__shared_ptr_access<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2, false, false>> = {<No data fields>}, _M_ptr = 0x0,
    _M_refcount = {_M_pi = 0x0}}}
__for_end = <optimized out>
folder = "/opt/cuda/nsight_compute"
i = 1
path = "/home/reee/.local/bin:/home/reee/go/bin:/opt/jython/bin/:/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/opt/android-sdk/platform-tools:/opt/cuda/bin:/opt/cuda/nsight_compute:/opt/cuda/n"...
delim = 58 ':'
start = 164
end = 188

It turned out to be that a path in $PATH that did not exist, so I added a pull request to your fork.

lockieluke commented 1 year ago

would this work on macOS

Toby222 commented 1 year ago

would this work on macOS

No idea!

KorigamiK commented 1 year ago

I'd be interested to know how much work is still required for this to be merged. Since this PR modifies a lot of code in the vendor libraries, at this point I'd rather bundle some of these with the repository itself instead of a submodule.

And thanks for you work :)

Toby222 commented 1 year ago

I'd be interested to know how much work is still required for this to be merged. Since this PR modifies a lot of code in the vendor libraries, at this point I'd rather bundle some of these with the repository itself instead of a submodule.

And thanks for you work :)

I don't understand wym by changing code in vendor ^^; I just updated the submodules in hopes that it'd fix some bugs regarding Wayland support.

Re: things that need to be done Last I checked, the biggest blocking thing was that the current version of cppUtils is broken and unfinished on Linux, and I wasn't smart enough to make it work. (hence me kinda stopping working on this for so long)

zyansheep commented 1 year ago

Compiled this PR (branch=linux) on NixOS, but got page fault in imgui font loading for some reason... At least it compiles!

Env packages: nix-shell -p pkgconfig cmake yasm xorg.libX11 xorg.libXrandr xorg.libXcursor xorg.libXi xorg.libXinerama gtk3 openssl pcre2 util-linux ffmpeg_5-full pipewire libva libvdpau libdrm gdb

Backtrace:

[2023-03-16 03:47:31]: GLFW window created

Thread 1 "MathAnimations" received signal SIGSEGV, Segmentation fault.
0x000000000081eb94 in ImFontAtlas::AddFont (this=this@entry=0xd9dfa0, font_cfg=0x7ffffffeaf10) at /home/zyansheep/Repos/MathAnimation/Animations/vendor/dearimgui/imgui_draw.cpp:2089
2089            new_font_cfg.DstFont = Fonts.back();
(gdb) bt
#0  0x000000000081eb94 in ImFontAtlas::AddFont (this=this@entry=0xd9dfa0, font_cfg=0x7ffffffeaf10) at /home/zyansheep/Repos/MathAnimation/Animations/vendor/dearimgui/imgui_draw.cpp:2089
#1  0x000000000081ed1c in ImFontAtlas::AddFontFromMemoryTTF (this=this@entry=0xd9dfa0, ttf_data=ttf_data@entry=0x7fffcc1f5010, ttf_size=388460, size_pixels=size_pixels@entry=14.7777777, 
    font_cfg_template=font_cfg_template@entry=0x7ffffffeafe0, glyph_ranges=glyph_ranges@entry=0x85bc58 <MathAnim::ImGuiLayer::init(MathAnim::Window const&)::iconRanges>)
    at /home/zyansheep/Repos/MathAnimation/Animations/vendor/dearimgui/imgui_draw.cpp:2176
#2  0x000000000081eec7 in ImFontAtlas::AddFontFromFileTTF (this=0xd9dfa0, filename=filename@entry=0x85b47d "assets/fonts/fa-solid-900.ttf", size_pixels=size_pixels@entry=14.7777777, 
    font_cfg_template=font_cfg_template@entry=0x7ffffffeb0d0, glyph_ranges=glyph_ranges@entry=0x85bc58 <MathAnim::ImGuiLayer::init(MathAnim::Window const&)::iconRanges>)
    at /home/zyansheep/Repos/MathAnimation/Animations/vendor/dearimgui/imgui_draw.cpp:2162
#3  0x00000000004722d9 in MathAnim::ImGuiLayer::init (window=...) at /home/zyansheep/Repos/MathAnimation/Animations/src/core/ImGuiLayer.cpp:56
#4  0x0000000000476c85 in MathAnim::ProjectApp::init () at /home/zyansheep/Repos/MathAnimation/Animations/src/core/ProjectApp.cpp:31
#5  0x000000000043a376 in main () at /home/zyansheep/Repos/MathAnimation/Animations/src/main.cpp:10