# SDL\_shadercross: Fix segfault when defines is NULL

**URL:** <https://discourse.libsdl.org/t/sdl-shadercross-fix-segfault-when-defines-is-null/56132>\
**Category:** SDL Commits\
**Created:** [December 19, 2024, 10:39pm UTC](https://discourse.libsdl.org/t/sdl-shadercross-fix-segfault-when-defines-is-null/56132 "2024-12-19T22:39:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [December 19, 2024, 10:39pm UTC](https://discourse.libsdl.org/t/sdl-shadercross-fix-segfault-when-defines-is-null/56132/1 "2024-12-19T22:39:50Z")

</div>

> <https://github.com/libsdl-org/SDL_shadercross/commit/864b6fbdc97ea21ac0c98265182c6bfae1efcbeb>

```diff
From 864b6fbdc97ea21ac0c98265182c6bfae1efcbeb Mon Sep 17 00:00:00 2001
From: cosmonaut <[EMAIL REDACTED]>
Date: Thu, 19 Dec 2024 14:39:43 -0800
Subject: [PATCH] Fix segfault when defines is NULL

---
 src/SDL_shadercross.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/SDL_shadercross.c b/src/SDL_shadercross.c
index 32db3e8..16df52c 100644
--- a/src/SDL_shadercross.c
+++ b/src/SDL_shadercross.c
@@ -409,11 +409,13 @@ static void *SDL_ShaderCross_INTERNAL_CompileUsingDXC(
         return NULL;
     }
 
- for (Uint32 i = 0; i < MAX_DEFINES; i += 1) {
- if (info->defines[i].name == NULL) {
- break;
+ if (info->defines != NULL) {
+ for (Uint32 i = 0; i < MAX_DEFINES; i += 1) {
+ if (info->defines[i].name == NULL) {
+ break;
+ }
+ numDefineStrings += 1;
         }
- numDefineStrings += 1;
     }
 
     char defineString[MAX_DEFINE_STRING_LENGTH];

```
