From 9e1721f58bb764e94590fa750a756c86983bc0a6 Mon Sep 17 00:00:00 2001 From: Simon Kellet Date: Thu, 4 Jun 2026 10:52:48 +0100 Subject: [PATCH] remove arena, replaced by temp also free'd SDL.Surfce --- main.odin | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/main.odin b/main.odin index 9772a41..65cb780 100644 --- a/main.odin +++ b/main.odin @@ -1,7 +1,7 @@ +#+vet explicit-allocators package main import "core:fmt" -import vmem "core:mem/virtual" import "core:os" import SDL "vendor:sdl2" @@ -18,24 +18,21 @@ print_usage :: proc() { } main :: proc() { - arena: vmem.Arena - arena_err := vmem.arena_init_growing(&arena) - ensure(arena_err == nil) - arena_allocator := vmem.arena_allocator(&arena) - defer vmem.arena_destroy(&arena) //clean up everything! - - file := Ppm_file{} - if len(os.args) > 3 || len(os.args) < 2 { print_usage() } + + file := Ppm_file{} filename := os.args[1] - if ok, err := load_ppm(&file, filename, arena_allocator); !ok { + if ok, err := load_ppm(&file, filename, context.temp_allocator); !ok { fmt.eprintfln("ERROR: Failed to load file '%s': %s ", filename, os.error_string(err)) os.exit(1) } - ppm_parse(&file, arena_allocator) + ppm_parse(&file, context.temp_allocator) + defer free_all(context.temp_allocator) //clear the temp + // Set the window size within the minimum or + // if the image is bigger, set the window size to that! window_width: i32 = i32( file.width, ); if i32(file.width) < WINDOW_WIDTH_MIN {window_width = WINDOW_WIDTH_MIN} @@ -43,10 +40,11 @@ main :: proc() { file.width, ); if i32(file.height) < WINDOW_WIDTH_MIN {window_height = WINDOW_HEIGHT_MIN} + // SDL Init sdl_init_error := SDL.Init(SDL.INIT_VIDEO) assert(sdl_init_error == 0, SDL.GetErrorString()) + defer SDL.Quit() // Defer quit at scope end - defer SDL.Quit() window := SDL.CreateWindow( WINDOW_TITLE, SDL.WINDOWPOS_CENTERED, @@ -55,26 +53,22 @@ main :: proc() { window_height, WINDOW_FLAGS, ) - assert(window != nil, SDL.GetErrorString()) defer SDL.DestroyWindow(window) surface := SDL.GetWindowSurface(window) + defer SDL.FreeSurface(surface) colour_bg := SDL.MapRGB(surface.format, 42, 42, 42) SDL.FillRect(surface, nil, colour_bg) - i := 0 pixel := SDL.Rect{0, 0, 1, 1} for y: i32 = 0; y < i32(file.height); y += 1 { for x: i32 = 0; x < i32(file.width); x += 1 { - red: u8 - green: u8 - blue: u8 - red = file.pixels[i].red - green = file.pixels[i].green - blue = file.pixels[i].blue + red: u8 = file.pixels[i].red + green: u8 = file.pixels[i].green + blue: u8 = file.pixels[i].blue pixel.x = x pixel.y = y