Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEST_Animate2D.cpp does not compile on ubuntu #365

Open
GeraldRyan opened this issue Mar 11, 2024 · 9 comments
Open

TEST_Animate2D.cpp does not compile on ubuntu #365

GeraldRyan opened this issue Mar 11, 2024 · 9 comments

Comments

@GeraldRyan
Copy link

Great codebase and fun project. I am pretty new to this and to C++ generally

As the subject says, the TEST_ANIMATE2D does not work. If you could point me in the right direction of a fix, I can maybe do a PR - if the fix is simple.

The other example files compile no problem, with the following command
g++ -o test_quickGUI examples/TEST_QuickGUI.cpp -I. -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17

When I do g++ -o test_quickGUI examples/TEST_Animate2D.cpp -I. -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17 I get the following list of errors:

In file included from ./utilities/olcUTIL_Animate2D.h:62,
                 from examples/TEST_Animate2D.cpp:56:
./utilities/olcUTIL_Geometry2D.h:485:24: error: conflicting declaration ‘typedef struct olc::v_2d<int> olc::vi2d’
  485 |  typedef v_2d<int32_t> vi2d;
      |                        ^~~~
In file included from examples/TEST_Animate2D.cpp:54:
./olcPixelGameEngine.h:739:31: note: previous declaration as ‘typedef struct olc::v2d_generic<int> olc::vi2d’
  739 |  typedef v2d_generic<int32_t> vi2d;
      |                               ^~~~
In file included from ./utilities/olcUTIL_Animate2D.h:62,
                 from examples/TEST_Animate2D.cpp:56:
./utilities/olcUTIL_Geometry2D.h:486:25: error: conflicting declaration ‘typedef struct olc::v_2d<unsigned int> olc::vu2d’
  486 |  typedef v_2d<uint32_t> vu2d;
      |                         ^~~~
In file included from examples/TEST_Animate2D.cpp:54:
./olcPixelGameEngine.h:740:32: note: previous declaration as ‘typedef struct olc::v2d_generic<unsigned int> olc::vu2d’
  740 |  typedef v2d_generic<uint32_t> vu2d;
      |                                ^~~~
In file included from ./utilities/olcUTIL_Animate2D.h:62,
                 from examples/TEST_Animate2D.cpp:56:
./utilities/olcUTIL_Geometry2D.h:487:22: error: conflicting declaration ‘typedef struct olc::v_2d<float> olc::vf2d’
  487 |  typedef v_2d<float> vf2d;
      |                      ^~~~
In file included from examples/TEST_Animate2D.cpp:54:
./olcPixelGameEngine.h:741:29: note: previous declaration as ‘typedef struct olc::v2d_generic<float> olc::vf2d’
  741 |  typedef v2d_generic<float> vf2d;
      |                             ^~~~
In file included from ./utilities/olcUTIL_Animate2D.h:62,
                 from examples/TEST_Animate2D.cpp:56:
./utilities/olcUTIL_Geometry2D.h:488:23: error: conflicting declaration ‘typedef struct olc::v_2d<double> olc::vd2d’
  488 |  typedef v_2d<double> vd2d;
      |                       ^~~~
In file included from examples/TEST_Animate2D.cpp:54:
./olcPixelGameEngine.h:742:30: note: previous declaration as ‘typedef struct olc::v2d_generic<double> olc::vd2d’
  742 |  typedef v2d_generic<double> vd2d;
      |                              ^~~~
In file included from examples/TEST_Animate2D.cpp:56:
./utilities/olcUTIL_Animate2D.h: In constructor ‘olc::utils::Animate2D::Frame::Frame(const olc::Renderable*, const olc::utils::geom2d::rect<int>&)’:
./utilities/olcUTIL_Animate2D.h:82:54: error: no match for ‘operator=’ (operand types are ‘olc::v_2d<int>’ and ‘olc::vi2d’ {aka ‘olc::v2d_generic<int>’})
   82 |     rectFrameSource.size = gfxSource->Sprite()->Size();
      |                                                      ^
In file included from ./utilities/olcUTIL_Animate2D.h:62,
                 from examples/TEST_Animate2D.cpp:56:
./utilities/olcUTIL_Geometry2D.h:218:26: note: candidate: ‘constexpr olc::v_2d<T>& olc::v_2d<T>::operator=(const olc::v_2d<T>&) [with T = int]’
  218 |   inline constexpr v_2d& operator=(const v_2d& v) = default;
      |                          ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:218:48: note:   no known conversion for argument 1 from ‘olc::vi2d’ {aka ‘olc::v2d_generic<int>’} to ‘const olc::v_2d<int>&’
  218 |   inline constexpr v_2d& operator=(const v_2d& v) = default;
      |                                    ~~~~~~~~~~~~^
./utilities/olcUTIL_Geometry2D.h: In instantiation of ‘constexpr auto olc::operator+(const olc::v_2d<TL>&, const TR&) [with TL = int; TR = olc::v2d_generic<int>]’:
examples/TEST_Animate2D.cpp:264:92:   required from here
./utilities/olcUTIL_Geometry2D.h:407:21: error: no match for ‘operator+’ (operand types are ‘const int’ and ‘const olc::v2d_generic<int>’)
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |               ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:392:24: note: candidate: ‘template<class T> constexpr auto olc::operator+(const olc::v_2d<TL>&)’
  392 |  inline constexpr auto operator + (const v_2d<T>& lhs)
      |                        ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:392:24: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:21: note:   mismatched types ‘const olc::v_2d<TL>’ and ‘const int’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |               ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:399:24: note: candidate: ‘template<class TL, class TR> constexpr auto olc::operator+(const TL&, const olc::v_2d<TR>&)’
  399 |  inline constexpr auto operator + (const TL& lhs, const v_2d<TR>& rhs)
      |                        ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:399:24: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:21: note:   ‘const olc::v2d_generic<int>’ is not derived from ‘const olc::v_2d<TR>’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |               ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:405:24: note: candidate: ‘template<class TL, class TR> constexpr auto olc::operator+(const olc::v_2d<TL>&, const TR&)’
  405 |  inline constexpr auto operator + (const v_2d<TL>& lhs, const TR& rhs)
      |                        ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:405:24: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:21: note:   mismatched types ‘const olc::v_2d<TL>’ and ‘const int’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |               ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:411:24: note: candidate: ‘template<class TL, class TR> constexpr auto olc::operator+(const olc::v_2d<TL>&, const olc::v_2d<TR>&)’
  411 |  inline constexpr auto operator + (const v_2d<TL>& lhs, const v_2d<TR>& rhs)
      |                        ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:411:24: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:21: note:   mismatched types ‘const olc::v_2d<TL>’ and ‘const int’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |               ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:407:34: error: no match for ‘operator+’ (operand types are ‘const int’ and ‘const olc::v2d_generic<int>’)
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |                            ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:392:24: note: candidate: ‘template<class T> constexpr auto olc::operator+(const olc::v_2d<TL>&)’
  392 |  inline constexpr auto operator + (const v_2d<T>& lhs)
      |                        ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:392:24: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:34: note:   mismatched types ‘const olc::v_2d<TL>’ and ‘const int’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |                            ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:399:24: note: candidate: ‘template<class TL, class TR> constexpr auto olc::operator+(const TL&, const olc::v_2d<TR>&)’
  399 |  inline constexpr auto operator + (const TL& lhs, const v_2d<TR>& rhs)
      |                        ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:399:24: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:34: note:   ‘const olc::v2d_generic<int>’ is not derived from ‘const olc::v_2d<TR>’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |                            ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:405:24: note: candidate: ‘template<class TL, class TR> constexpr auto olc::operator+(const olc::v_2d<TL>&, const TR&)’
  405 |  inline constexpr auto operator + (const v_2d<TL>& lhs, const TR& rhs)
      |                        ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:405:24: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:34: note:   mismatched types ‘const olc::v_2d<TL>’ and ‘const int’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |                            ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:411:24: note: candidate: ‘template<class TL, class TR> constexpr auto olc::operator+(const olc::v_2d<TL>&, const olc::v_2d<TR>&)’
  411 |  inline constexpr auto operator + (const v_2d<TL>& lhs, const v_2d<TR>& rhs)
      |                        ^~~~~~~~
./utilities/olcUTIL_Geometry2D.h:411:24: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:34: note:   mismatched types ‘const olc::v_2d<TL>’ and ‘const int’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |                            ~~~~~~^~~~~
./utilities/olcUTIL_Geometry2D.h:407:10: error: class template argument deduction failed:
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./utilities/olcUTIL_Geometry2D.h:407:10: error: no matching function for call to ‘v_2d()’
./utilities/olcUTIL_Geometry2D.h:215:20: note: candidate: ‘template<class T> v_2d(const olc::v_2d<T>&)-> olc::v_2d<T>’
  215 |   inline constexpr v_2d(const v_2d& v) = default;
      |                    ^~~~
./utilities/olcUTIL_Geometry2D.h:215:20: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:10: note:   candidate expects 1 argument, 0 provided
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./utilities/olcUTIL_Geometry2D.h:211:20: note: candidate: ‘template<class T> v_2d(T, T)-> olc::v_2d<T>’
  211 |   inline constexpr v_2d(T _x, T _y) : x(_x), y(_y)
      |                    ^~~~
./utilities/olcUTIL_Geometry2D.h:211:20: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:10: note:   candidate expects 2 arguments, 0 provided
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./utilities/olcUTIL_Geometry2D.h:208:20: note: candidate: ‘template<class T> v_2d()-> olc::v_2d<T>’
  208 |   inline constexpr v_2d() = default;
      |                    ^~~~
./utilities/olcUTIL_Geometry2D.h:208:20: note:   template argument deduction/substitution failed:
./utilities/olcUTIL_Geometry2D.h:407:10: note:   couldn’t deduce template parameter ‘T’
  407 |   return v_2d(lhs.x + rhs, lhs.y + rhs);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./utilities/olcUTIL_Geometry2D.h:407:10: error: expression list treated as compound expression in functional cast [-fpermissive]
examples/TEST_Animate2D.cpp: In member function ‘virtual bool TEST_Animate2D::OnUserUpdate(float)’:
examples/TEST_Animate2D.cpp:264:127: error: invalid use of void expression
  264 | pos, frame.GetSourceImage()->Decal(), frame.GetSourceRect().pos + vOffset, frame.GetSourceRect().size);
      |                                                        
@sigonasr2
Copy link

sigonasr2 commented Mar 12, 2024

The Geometry util has undergone some major reworks and because of that it has broken this example. You can fix it by doing two things:

  • Swap the order of both #include "utilities/olcUTIL_Geometry2D.h" and #include "olcPixelGameEngine.h" in olcUTIL_Animate2D.h and TEST_Animate2D.cpp so they look like this:
#include "utilities/olcUTIL_Animate2D.h"
#include "olcPixelGameEngine.h"
  • Add #define OLC_IGNORE_VEC2D in TEST_Animate2D.cpp above #include "utilities/olcUTIL_Animate2D.h"

Should be good to go after that.

@GeraldRyan
Copy link
Author

It compiled! And it ran but it immediately got a segfault

[1] 30019 segmentation fault (core dumped) ./test_animate

Hey that's still progress

@sigonasr2
Copy link

This is because you have to supply your own image to load (it tries to load "./assets/MegaSprite1.png"). I don't have the image this example provides, but if you have a spritesheet, you can tailor the animation system to work for that sheet using the example file as a guide.

@GeraldRyan
Copy link
Author

As to sprites and spritesheets, I'm new to them. I don't want to get too much down that rabbit hole because I'm more interested in the math and algorithms vs the game design but they're on my radar now as a thing to consider.

I plugged in a static creative commons licensed mario png and it works, albiet probably not as expected. It doesn't crash. It shards the thing during animation in a kind of cool way.

Anyway I opened a PR for these fixes. Feel free to update with a better spritesheet or make changes!!!

@brmarkus
Copy link

brmarkus commented May 4, 2024

In addition to the above I needed to add #include <array> to the file olcUTIL_Geometry2D.h and to add template to turn

return !(p.x < r.pos.x || p.y < r.pos.y ||

into

return !(p.template x < r.pos.x || p.template y < r.pos.y ||

in file olcUTIL_Geometry2D.h as well.

(using "g++ (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0" under Ubuntu 22.04 LTS)

@Moros1138
Copy link
Collaborator

Regarding the olcUTIL_Geometry2d.h it should be noted that has a separate repo where development on it is actively progressing. Before patching the header here, check to see that the issue hasn't already been solved in the other repo.

Unfortunately, the header provided in the PGE repo doesn't match.

@Moros1138
Copy link
Collaborator

g++ -o test_quickGUI examples/TEST_QuickGUI.cpp -I. -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17
g++ -o test_quickGUI examples/TEST_Animate2D.cpp -I. -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17

we require C++20, you're compiling with C++17

@brmarkus
Copy link

brmarkus commented May 5, 2024

Compilation followed the Wiki under "https://github.com/OneLoneCoder/olcPixelGameEngine/wiki/Compiling-on-Linux#building":

g++ -o olcExampleProgram olcExampleProgram.cpp -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17

See also the latest version of "https://github.com/OneLoneCoder/olcPixelGameEngine/blob/master/olcPixelGameEngine.h#L73":

Compiling in Linux

 You will need a modern C++ compiler, so update yours!
 To compile use the command:

 g++ -o YourProgName YourSource.cpp -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17

Where is the "C++20" coming from? Maybe you are referring to another branch?

@Moros1138
Copy link
Collaborator

Good to point that out. That's just for PGE itself, the extensions and utilities might have differing requirements. The wiki doesn't reflect that..... yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants