From 0ff24117dd41285cabc76498c7417fe0cac87644 Mon Sep 17 00:00:00 2001 From: doylet Date: Sat, 28 Mar 2026 17:54:00 +1100 Subject: [PATCH] Fix M2x3MulRect and make profiler null-safe --- Source/Base/dn_base.cpp | 26 ++++++++++++++++---------- Source/Extra/dn_demo.cpp | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Source/Base/dn_base.cpp b/Source/Base/dn_base.cpp index f25008b..c0cf6da 100644 --- a/Source/Base/dn_base.cpp +++ b/Source/Base/dn_base.cpp @@ -3903,7 +3903,7 @@ DN_API DN_Profiler DN_ProfilerInit(DN_ProfilerAnchor *anchors, DN_USize count, D DN_API DN_USize DN_ProfilerFrameCount(DN_Profiler const *profiler) { - DN_USize result = profiler->anchors_count / profiler->anchors_per_frame; + DN_USize result = profiler ? profiler->anchors_count / profiler->anchors_per_frame : 0; return result; } @@ -3925,7 +3925,7 @@ DN_API DN_ProfilerAnchorArray DN_ProfilerFrameAnchors(DN_Profiler *profiler) DN_API DN_ProfilerZone DN_ProfilerBeginZone(DN_Profiler *profiler, DN_Str8 name, DN_U16 anchor_index) { DN_ProfilerZone result = {}; - if (profiler->paused) + if (!profiler || profiler->paused) return result; DN_Assert(anchor_index < profiler->anchors_per_frame); @@ -3949,7 +3949,7 @@ DN_API DN_ProfilerZone DN_ProfilerBeginZone(DN_Profiler *profiler, DN_Str8 name, DN_API void DN_ProfilerEndZone(DN_Profiler *profiler, DN_ProfilerZone zone) { - if (profiler->paused) + if (!profiler || profiler->paused) return; DN_Assert(zone.anchor_index < profiler->anchors_per_frame); @@ -3973,7 +3973,7 @@ DN_API void DN_ProfilerEndZone(DN_Profiler *profiler, DN_ProfilerZone zone) DN_API void DN_ProfilerNewFrame(DN_Profiler *profiler) { - if (profiler->paused) + if (!profiler || profiler->paused) return; // NOTE: End the frame's zone @@ -3996,7 +3996,7 @@ DN_API void DN_ProfilerNewFrame(DN_Profiler *profiler) DN_API void DN_ProfilerDump(DN_Profiler *profiler) { - if (profiler->frame_index == 0) + if (!profiler || profiler->frame_index == 0) return; DN_USize frame_index = profiler->frame_index - 1; @@ -5979,11 +5979,17 @@ DN_API DN_V2F32 DN_M2x3MulV2F32(DN_M2x3 m1, DN_V2F32 v2) DN_API DN_Rect DN_M2x3MulRect(DN_M2x3 m1, DN_Rect rect) { - DN_2V2F32 rect_range = DN_RectRange(rect); - DN_2V2F32 result_range = {}; - result_range.min = DN_M2x3MulV2F32(m1, rect_range.min); - result_range.max = DN_M2x3MulV2F32(m1, rect_range.max); - DN_Rect result = DN_RectFrom2V2(result_range.min, result_range.max - result_range.min); + DN_2V2F32 rect_range = DN_RectRange(rect); + DN_V2F32 m1_min = DN_M2x3MulV2F32(m1, rect_range.min); + DN_V2F32 m1_max = DN_M2x3MulV2F32(m1, rect_range.max); + + // NOTE: Re-establish AABB of the rectangle because it has gone through an arbitrary + // vertex transformation. + DN_2V2F32 result_range = {}; + result_range.min = DN_V2F32Min(m1_min, m1_max); + result_range.max = DN_V2F32Max(m1_min, m1_max); + + DN_Rect result = DN_RectFrom2V2(result_range.min, DN_V2F32Abs(result_range.max - result_range.min)); return result; } diff --git a/Source/Extra/dn_demo.cpp b/Source/Extra/dn_demo.cpp index e3e56ae..d9d3961 100644 --- a/Source/Extra/dn_demo.cpp +++ b/Source/Extra/dn_demo.cpp @@ -40,7 +40,7 @@ void DN_Demo() // NOTE: DN_BytesFromHex { unsigned char bytes[2]; - DN_USize bytes_written = DN_BytesFromHexStr8(DN_Str8Lit("0xFACE"), bytes, sizeof(bytes)); + DN_USize bytes_written = DN_BytesFromHex(DN_Str8Lit("0xFACE"), bytes, sizeof(bytes)); DN_Assert(bytes_written == 2); DN_Assert(bytes[0] == 0xFA); DN_Assert(bytes[1] == 0xCE);