|
Unexpected error in primitive al_draw_circle (aka Return Of The Bad Programmer) |
mumu1000
Member #16,842
April 2018
|
Hello everybody ! here's my code: main.cpp 1#include <iostream>
2#include <string>
3#include <chrono>
4#include <thread>
5#include "allegro5/allegro.h"
6#include "allegro5/allegro_color.h"
7#include "allegro5/allegro_primitives.h"
8
9int main(int argc, char **argv)
10{
11 if (al_init() && al_init_primitives_addon())
12 {
13 std::cout<<"It Works";
14 }else
15 {
16 std::cout << "Allegro Not Loaded";
17 return 1;
18 }
19 al_set_new_display_flags(ALLEGRO_FRAMELESS+ALLEGRO_FULLSCREEN_WINDOW);
20 ALLEGRO_DISPLAY * mainDisplay = al_create_display(1800,1000);
21
22 al_clear_to_color(al_map_rgb(20,20,20));
23 Planet* testPlanet = new Planet(100,100);
24 testPlanet->draw();
25 al_flip_display();
26 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
27
28 al_shutdown_primitives_addon();
29 al_destroy_display(mainDisplay);
30 return 0;
31}
Planet.h 1#include "allegro5/color.h"
2#include "allegro5/allegro_primitives.h"
3class Planet
4{
5 public:
6 Planet();
7 Planet(float xPos, float yPos);
8 virtual ~Planet();
9 virtual void const draw();
10 float const getXPos(){return m_xPos;};
11 float const getYPos(){return m_yPos;};
12 void setXPos(float xPos){m_xPos = xPos;};
13 void setYPos(float yPos){m_yPos = yPos;};
14
15 protected:
16 float m_xPos;
17 float m_yPos;
18
19 private:
20 const static ALLEGRO_COLOR drawedColor;
21};
Planet.cpp 1#include "Planet.h"
2
3const ALLEGRO_COLOR Planet::drawedColor = al_map_rgb(20,200,20);
4
5Planet::Planet()
6{
7 m_xPos = 0;
8 m_yPos = 0;
9}
10Planet::Planet(float xPos, float yPos)
11{
12 m_xPos = xPos;
13 m_yPos = yPos;
14}
15
16Planet::~Planet()
17{
18
19}
20void const Planet::draw()
21{
22 al_draw_circle(10+(m_xPos*30),10+(m_yPos*30),8,Planet::drawedColor,3);
23}
What i figured out : Please help ! Have a great day ! Edit: The problem is not coming from here (i simplified the problem in this forum thread, but i think the problem comes from another part of the code)7 Edit 2: This is so confusing, i cant get it to work. Do you see any mistakes i've made in these sources ? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I see one thing. You're using a global const ALLEGRO_COLOR and caling al_map_rgb outside of al_init() because global constructors get called before main. Calling allegro functions before al_init can give undefined behavior. EDIT Post a minimal working example that compiles if the above didn't fix the problem. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
mumu1000
Member #16,842
April 2018
|
Edgar Reynaldo said: I see one thing. You're using a global const ALLEGRO_COLOR and caling al_map_rgb outside of al_init() because global constructors get called before main. Calling allegro functions before al_init can give undefined behavior. Oh ! Very interesting ! Thx for the answer ! Edgar Reynaldo said: Also, that code won't compile because you didn't #include "planet.h" Oh yea my bad, this error comes from when i tried to synthetize the problem and refactored the code to describe my problem better. (As i told, my code compiles ^^) Edgar Reynaldo said: Post a minimal working example that compiles if the above didn't fix the problem. This example is not relevant anymore, i've made a new post, with all the actual sources, and one new hell of an issue ;p Great day ! |
|