From 553673878a1f7b80600d756484e9f9d7549160e3 Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Mon, 12 Feb 2024 11:34:31 +0100 Subject: [PATCH] Fix label crash due to stack allocated string --- Source/Render/sokol/SokolRender.cpp | 3 ++- Source/Render/sokol/SokolRenderTexture.cpp | 4 ++-- Source/Render/sokol/SokolResources.cpp | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/Render/sokol/SokolRender.cpp b/Source/Render/sokol/SokolRender.cpp index 429b5e5e0..880048127 100644 --- a/Source/Render/sokol/SokolRender.cpp +++ b/Source/Render/sokol/SokolRender.cpp @@ -135,7 +135,7 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres //Create empty texture sg_image_desc* imgdesc = new sg_image_desc(); - imgdesc->label = "EmptySlotTexture"; + imgdesc->label = nullptr; imgdesc->width = imgdesc->height = 64; imgdesc->wrap_u = imgdesc->wrap_v = SG_WRAP_REPEAT; imgdesc->pixel_format = SG_PIXELFORMAT_RGBA8; @@ -152,6 +152,7 @@ int cSokolRender::Init(int xScr, int yScr, int mode, SDL_Window* wnd, int Refres #else emptyTexture = new SokolTexture2D(imgdesc); #endif + emptyTexture->label = "EmptySlotTexture"; RenderSubmitEvent(RenderEvent::INIT, "Sokol done"); return UpdateRenderMode(); diff --git a/Source/Render/sokol/SokolRenderTexture.cpp b/Source/Render/sokol/SokolRenderTexture.cpp index e0d06d261..1f127ab02 100644 --- a/Source/Render/sokol/SokolRenderTexture.cpp +++ b/Source/Render/sokol/SokolRenderTexture.cpp @@ -28,9 +28,8 @@ int cSokolRender::CreateTexture(cTexture* Texture, cFileImage* FileImage, bool e delete img; img = nullptr; } - std::string label = Texture->GetName() + std::to_string(i); sg_image_desc* desc = new sg_image_desc(); - desc->label = label.c_str(); + desc->label = nullptr; //Added later desc->width = dx; desc->height = dy; desc->wrap_u = desc->wrap_v = SG_WRAP_REPEAT; @@ -124,6 +123,7 @@ int cSokolRender::CreateTexture(cTexture* Texture, cFileImage* FileImage, bool e #else img = new SokolTexture2D(desc); #endif + img->label = Texture->GetName() + std::to_string(i); } Texture->GetFrameImage(i)->sg = img; diff --git a/Source/Render/sokol/SokolResources.cpp b/Source/Render/sokol/SokolResources.cpp index d4022f92b..a92d3b4a3 100644 --- a/Source/Render/sokol/SokolResources.cpp +++ b/Source/Render/sokol/SokolResources.cpp @@ -151,8 +151,8 @@ void SokolTexture2D::update() { if (desc) { #ifdef PERIMETER_DEBUG - if (desc->label) { - label = desc->label; + if (!label.empty()) { + desc->label = label.c_str(); } #endif xassert(desc->usage == SG_USAGE_IMMUTABLE || data);