Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - MrKeviscool

Pages: [1]
1
Graphics / Re: segfault displaying dynamic array rectangle
« on: July 10, 2024, 03:55:10 pm »
it works! thanks so much :D

2
Graphics / [SOLVED] segfault displaying dynamic array rectangle
« on: July 10, 2024, 01:46:51 pm »
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 :D

Pages: [1]
anything