Skip to content

Commit

Permalink
Fix label crash due to stack allocated string
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Feb 12, 2024
1 parent 54089f4 commit 5536738
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Source/Render/sokol/SokolRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Source/Render/sokol/SokolRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Source/Render/sokol/SokolResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5536738

Please sign in to comment.