segfault fixed

parent ec1169ab
CFLAGS = -Wno-unused-command-line-argument -Wno-missing-field-initializers -Wall -Wextra -Wpedantic -lm -fopenmp
DEBUG_CFLAGS = -g -DDEBUG
DEBUG_CFLAGS = -g -DDEBUG -pg -O0
LDLIBS = $(shell pkg-config --libs sdl2 SDL2_ttf)
CFLAGS := $(CFLAGS) -O3
CFLAGS := $(CFLAGS) -pg
#CFLAGS := $(CFLAGS) -O3
CFLAGS := $(CFLAGS) $(DEBUG_CFLAGS)
SRCDIR=src
BIULDDIR=build
# compiler
CC = gcc
#CC = clang
#CC = gcc
CC = clang
OBJS = $(BIULDDIR)/mouse.o $(BIULDDIR)/ui.o
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -44,6 +44,7 @@ typedef struct {
void
calculate_set(Array *arr, int height, int width, ViewInfo view)
{
//printf("arr size: %d, screen %d\n", arr->size, height * width);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
double real = view.x_min + (x * (view.x_max - view.x_min)) / width;
......@@ -53,16 +54,15 @@ calculate_set(Array *arr, int height, int width, ViewInfo view)
int iterations = mandelbrot(c);
if (iterations == MAX_ITERATIONS){
arr->pointer[x * width + y].r = 0;
arr->pointer[x * width + y].g = 0;
arr->pointer[x * width + y].b = 0;
arr->pointer[x * height + y].r = 0;
arr->pointer[x * height + y].g = 0;
arr->pointer[x * height + y].b = 0;
} else {
double t = (double)iterations / MAX_ITERATIONS;
t = 0.5 + 0.5 * cos(log(t + 0.0001) * 3.0);
arr->pointer[x * width + y].r = 255 * t;
arr->pointer[x * width + y].g = 255 * t * 0.4;
arr->pointer[x * width + y].b = 255 * t * 0.2;
arr->pointer[x * height + y].r = 255 * t;
arr->pointer[x * height + y].g = 255 * t * 0.4;
arr->pointer[x * height + y].b = 255 * t * 0.2;
}
}
}
......@@ -74,18 +74,18 @@ render_cl(Array *arr, App *app, ViewInfo view, int start_x, int start_y) {
SDL_SetRenderDrawColor(app->renderer, 0, 0, 50, 255);
SDL_RenderClear(app->renderer);
if (arr->size < app->win_height * app->win_width){
if (arr->size < app->win_height * app->win_width * sizeof(Color)){
arr->pointer = realloc(arr->pointer, app->win_height * app->win_width * sizeof(Color));
arr->size = app->win_height * app->win_width;
arr->size = app->win_height * app->win_width * sizeof(Color);
}
calculate_set(arr, app->win_height, app->win_width, view);
for (int x = 0; x < app->win_width; x++) {
for (int y = 0; y < app->win_height; y++) {
SDL_SetRenderDrawColor(app->renderer,
arr->pointer[x * app->win_width + y].r,
arr->pointer[x * app->win_width + y].g,
arr->pointer[x * app->win_width + y].b,
arr->pointer[x * app->win_height + y].r,
arr->pointer[x * app->win_height + y].g,
arr->pointer[x * app->win_height + y].b,
255);
SDL_RenderDrawPoint(app->renderer, x, y);
}
......@@ -170,7 +170,7 @@ main(int argc, char *argv[])
Array screen = {
malloc(app.win_height * app.win_width * sizeof(Color)),
app.win_height * app.win_width
app.win_height * app.win_width * sizeof(Color)
};
......@@ -189,7 +189,7 @@ main(int argc, char *argv[])
case SDL_WINDOWEVENT:
if(event.window.event == SDL_WINDOWEVENT_RESIZED){
SDL_GetWindowSize(app.window, &app.win_width, &app.win_height);
}
}
break;
case SDL_KEYDOWN:
switch (event.key.keysym.scancode)
......@@ -225,12 +225,12 @@ main(int argc, char *argv[])
break;
}
}
SDL_SetRenderDrawColor(app.renderer, 0xff, 0xff, 0xff, 0xff);
SDL_RenderClear(app.renderer);
//drawing happens here
SDL_SetRenderDrawColor(app.renderer, 0xff, 0xff, 0xff, 0xff);
SDL_RenderClear(app.renderer);
render_cl(&screen, &app, view, 0, 0);
// render(&app,
// view,
// 0, app.win_width,
......@@ -244,9 +244,10 @@ main(int argc, char *argv[])
render_ui(&ui, app.renderer, view, fps);
SDL_RenderPresent(app.renderer);
}
//SDL_FreeSurface(app.surfaceA);
free(screen.pointer);
SDL_DestroyRenderer(app.renderer);
SDL_DestroyWindow(app.window);
SDL_Quit();
......
#include "mandelbrot.h"
void
void
handle_mouse(SDL_Event event, Mouse* mouse, ViewInfo* view) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment