fix memory error during optimization

This commit is contained in:
jacob 2024-03-06 20:41:14 -06:00
parent ed9841c1b1
commit fa5fdbe955
3 changed files with 21 additions and 19 deletions

View File

@ -174,9 +174,9 @@ if (RTC)
message(FATAL_ERROR "CRTLIB (C runtime library) Must be enabled when compiling with RTC (runtime checks)") message(FATAL_ERROR "CRTLIB (C runtime library) Must be enabled when compiling with RTC (runtime checks)")
endif() endif()
# NOTE: Adress sanitizer is disable for now because for some reason it's hiding local variables in debug mode. # NOTE: Adress sanitizer is disable for now because for some reason it's hiding local variables in debug mode.
set(COMPILER_FLAGS "${COMPILER_FLAGS} -DRTC=1") # set(COMPILER_FLAGS "${COMPILER_FLAGS} -DRTC=1")
# set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=undefined -fno-sanitize=alignment -DRTC=1") # set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=undefined -fno-sanitize=alignment -DRTC=1")
# set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=undefined -fsanitize-trap=undefined -fno-sanitize=alignment -DRTC=1") set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=undefined -fsanitize-trap=undefined -fno-sanitize=alignment -DRTC=1")
# set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -DRTC=1") # set(COMPILER_FLAGS "${COMPILER_FLAGS} -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -DRTC=1")
endif() endif()
@ -193,7 +193,7 @@ if (UNOPTIMIZED)
set(COMPILER_FLAGS "${COMPILER_FLAGS} -O0 -DUNOPTIMIZED=1") set(COMPILER_FLAGS "${COMPILER_FLAGS} -O0 -DUNOPTIMIZED=1")
set(LINKER_FLAGS "${LINKER_FLAGS} -O0") set(LINKER_FLAGS "${LINKER_FLAGS} -O0")
else() else()
set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -flto -fwhole-program") set(COMPILER_FLAGS "${COMPILER_FLAGS} -O3 -flto")
set(LINKER_FLAGS "${LINKER_FLAGS} -O3 -flto -fwhole-program") set(LINKER_FLAGS "${LINKER_FLAGS} -O3 -flto -fwhole-program")
endif() endif()

View File

@ -110,12 +110,16 @@ extern "C" {
#define CT_ASSERT2(cond, line) CT_ASSERT3(cond, line) #define CT_ASSERT2(cond, line) CT_ASSERT3(cond, line)
#define CT_ASSERT(cond) CT_ASSERT2(cond, __LINE__) #define CT_ASSERT(cond) CT_ASSERT2(cond, __LINE__)
#if RTC #if DEBINFO
/* For use after a static 'L' state variable is declared. This will create a /* For use after a static 'L' state variable is declared. This will create a
* variable that points to the 'L' variable and is kept alive (so that the * variable that points to the 'L' variable and is kept alive (so that the
* debugger can reference the state with a variable other than 'L') */ * debugger can reference the state with a variable other than 'L') */
#define DEBUG_LVAR(var) ,__attribute((used)) *var = &L; # define DEBUG_LVAR(var) ,__attribute((used)) *var = &L;
#else
# define DEBUG_LVAR(var)
#endif
#if RTC
#define ASSERT(cond) ((cond) ? 1 : (__builtin_trap(), 0)) #define ASSERT(cond) ((cond) ? 1 : (__builtin_trap(), 0))
#define DEBUGBREAK __builtin_debugtrap() #define DEBUGBREAK __builtin_debugtrap()
@ -134,9 +138,6 @@ extern "C" {
#else #else
#define DEBUG_VAR_GLOBAL(type, var, value)
#define DEBUG_LVAR(var)
#define ASSERT(cond) (void)(0) #define ASSERT(cond) (void)(0)
#define DEBUGBREAK #define DEBUGBREAK
#define ASAN_POISON(addr, size) #define ASAN_POISON(addr, size)

View File

@ -778,19 +778,19 @@ INTERNAL void user_update(void)
/* Present */ /* Present */
i32 vsync = VSYNC_ENABLED; i32 vsync = VSYNC_ENABLED;
struct renderer_canvas **canvases = NULL; struct renderer_canvas **canvases = arena_dry_push(scratch.arena, struct renderer_canvas *);
u64 canvases_count = 0; u64 canvases_count = 0;
{
if (t0->id <= 0 || t1->id <= 0) { /* Only render world if not on first frame */
/* Don't render world on first frame */ if (t0->id > 0 && t1->id > 0) {
struct renderer_canvas *present_canvases[] = { L.ui_canvas }; *arena_push(scratch.arena, struct renderer_canvas *) = L.world_canvas;
canvases = present_canvases; ++canvases_count;
canvases_count = ARRAY_COUNT(present_canvases);
} else {
struct renderer_canvas *present_canvases[] = { L.world_canvas, L.ui_canvas };
canvases = present_canvases;
canvases_count = ARRAY_COUNT(present_canvases);
} }
*arena_push(scratch.arena, struct renderer_canvas *) = L.ui_canvas;
++canvases_count;
}
renderer_canvas_present(canvases, canvases_count, L.screen_size.x, L.screen_size.y, vsync); renderer_canvas_present(canvases, canvases_count, L.screen_size.x, L.screen_size.y, vsync);
scratch_end(scratch); scratch_end(scratch);
@ -806,6 +806,7 @@ INTERNAL void user_thread_entry_point(void *arg)
sys_timestamp_t last_frame_ts = 0; sys_timestamp_t last_frame_ts = 0;
f64 target_dt = USER_FPS > 0 ? (1.0 / USER_FPS) : 0; f64 target_dt = USER_FPS > 0 ? (1.0 / USER_FPS) : 0;
while (!L.shutdown) { while (!L.shutdown) {
__profscope(user_update_w_sleep); __profscope(user_update_w_sleep);
sleep_frame(last_frame_ts, target_dt); sleep_frame(last_frame_ts, target_dt);