Hi all,
probably a silly mistake on my behalf but i cant figure out for the life of me why this program can successfully display the dimensions of the rectangle but cant actually draw it without a seg-fault. (i know the window will disappear instantly)
i know i can use other data-types but i would preferably like to allocate arrays myself.
any help would be greatly appreciated.
#include <iostream>
#include <SFML/Graphics.hpp>
sf::RenderWindow window(sf::VideoMode(1920, 1080), "window", sf::Style::Fullscreen);
int main(){
sf::RectangleShape** recarr = (sf::RectangleShape **)malloc(sizeof(sf::RectangleShape *));
recarr[0] = (sf::RectangleShape *)malloc(sizeof(sf::RectangleShape));
recarr[0][0] = sf::RectangleShape(sf::Vector2f(30, 100));
window.clear();
std::cout << "width of block: " << recarr[0][0].getSize().x << " bytes: " << sizeof(sf::RectangleShape) << std::endl; //this works
window.draw(recarr[0][0]); //this doesn't
window.display(); //this works
}
returns:
width of block: 30 bytes: 344
[1] 40165 segmentation fault ./t
window.draw(sf::RectangleShape(sf::Vector2f( 100, 30)));
(also just doing window.draw(sf::RectangleShape(sf::Vector2f( 100, 30))) works if that changes anything)
i appreciate it