Hi,
I'm having a little trouble with this. First of all, this is for a simple graphics library that I was writing.
What I'm doing is making it possible to declare multiple "virtual screens", with dimensions of the programmer's choice. For this, I need to dynamically allocate enough memory based on the number of pixels the screen will contain.
The function that allocates this memory seems to work only once in my program, then fails (with a segfault) every other time I call it. I think the issue may be the way I'm passing around the virtual screen (screen_t
). The way I implemented it, was that the function new_screen
returns not a pointer, but the actual screen itself. I'm thinking maybe that was a mistake. Additionally, when a function, such as set_current_screen
needs a screen as one of its arguments, it's passed the address, like this:
set_current_screen(&screen_variable);
Is this the right way to go about that? Is this what's causing the segfault when I call new_screen
?
Thanks in advance. The code is a header file (very incomplete), and a c file that draws some rects on one screen, tries to make another, gets a segfault. Here they are: