# Critical SDL 1.3 patch

**URL:** <https://discourse.libsdl.org/t/critical-sdl-1-3-patch/16134>\
**Category:** SDL Development\
**Created:** [March 22, 2009, 2:41am UTC](https://discourse.libsdl.org/t/critical-sdl-1-3-patch/16134 "2009-03-22T02:41:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mason\_Wheeler](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/b9bd4f/32.png) [@Mason\_Wheeler](https://discourse.libsdl.org/u/Mason_Wheeler)\
**Post date:** [March 22, 2009, 2:41am UTC](https://discourse.libsdl.org/t/critical-sdl-1-3-patch/16134/1 "2009-03-22T02:41:52Z")

</div>

Displaying a window created with SDL\_CreateWindowFrom was causing stack overflows for me under certain conditions. After far too much work trying to get Visual Studio’s debugger to play nice with a program written in Delphi, I tracked it down to a nasty reentrancy cycle in the WndProc handling. Here’s a patch that fixes the problem:

Index: SDL\_win32events.c===================================================================  
— SDL\_win32events.c (revision 4462)  
+++ SDL\_win32events.c (working copy)  
@@ -570,6 +570,17 @@  
}  
return (0);

- 

```
   /* If this isn't our window, we don't need to repaint the frame.

```

- 

```
      This fixes a reentrancy issue that can cause stack overflows with foreign windows.

```

- 

```
      3/21/09 Mason Wheeler */

```

- case WM\_NCPAINT:
- 

```
   {

```

- 

```
       if (SDL_GetWindowFlags(data->windowID) && SDL_WINDOW_FOREIGN) {

```

- 

```
           return(0);

```

- 

```
       }

```

- 

```
       break;

```

- 

```
   }

```

- 

```
   /* We'll do our own drawing, prevent flicker */

```

case WM\_ERASEBKGND:  
{

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [March 23, 2009, 2:04am UTC](https://discourse.libsdl.org/t/critical-sdl-1-3-patch/16134/2 "2009-03-23T02:04:43Z")

</div>

> Displaying a window created with SDL\_CreateWindowFrom was causing stack overflows for me under certain conditions. After far too much work trying to get Visual Studio’s debugger to play nice with a program written in Delphi, I tracked it down to a nasty reentrancy cycle in the WndProc handling. Here’s a patch that fixes the problem:

Thanks, this is in subversion!

See ya,  
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [March 23, 2009, 2:09am UTC](https://discourse.libsdl.org/t/critical-sdl-1-3-patch/16134/3 "2009-03-23T02:09:06Z")

</div>

> Displaying a window created with SDL\_CreateWindowFrom was causing stack overflows for me under certain conditions. After far too much work trying to get Visual Studio’s debugger to play nice with a program written in Delphi, I tracked it down to a nasty reentrancy cycle in the WndProc handling. Here’s a patch that fixes the problem:

Thanks! This patch is applied to subversion.

See ya,  
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

---

<div class="post-metadata">

**Author:** ![David\_Turner](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/cc9497/32.png) [@David\_Turner](https://discourse.libsdl.org/u/David_Turner)\
**Post date:** [March 24, 2009, 12:35pm UTC](https://discourse.libsdl.org/t/critical-sdl-1-3-patch/16134/4 "2009-03-24T12:35:25Z")

</div>

Are you sure you don’t want & instead of && ?On Sun, Mar 22, 2009 at 3:41 AM, Mason Wheeler wrote:

> Displaying a window created with SDL\_CreateWindowFrom was causing stack  
> overflows for me under certain conditions. After far too much work trying  
> to get Visual Studio’s debugger to play nice with a program written in  
> Delphi, I tracked it down to a nasty reentrancy cycle in the WndProc  
> handling. Here’s a patch that fixes the problem:
> 
> # Index: SDL\_win32events.c
> 
> — SDL\_win32events.c (revision 4462)  
> +++ SDL\_win32events.c (working copy)  
> @@ -570,6 +570,17 @@  
> }  
> return (0);
> 
> - 
> 
> ```
> /* If this isn't our window, we don't need to repaint the frame.
> 
> ```
> 
> - 
> 
> ```
> This fixes a reentrancy issue that can cause stack overflows
> 
> ```
> 
> with foreign windows.
> 
> - 
> 
> ```
> 3/21/09 Mason Wheeler */
> 
> ```
> 
> - case WM\_NCPAINT:
> - 
> 
> ```
> {
> 
> ```
> 
> - 
> 
> ```
> if (SDL_GetWindowFlags(data->windowID) && SDL_WINDOW_FOREIGN)
> 
> ```
> 
> {
> 
> - 
> 
> ```
> return(0);
> 
> ```
> 
> - 
> 
> ```
> }
> 
> ```
> 
> - 
> 
> ```
> break;
> 
> ```
> 
> - 
> 
> ```
> }
> 
> ```
> 
> - 
> 
> ```
> /* We'll do our own drawing, prevent flicker */
> 
> ```
> 
> case WM\_ERASEBKGND:  
> {
> 
> * * *
> 
> SDL mailing list  
> SDL at [lists.libsdl.org](http://lists.libsdl.org)  
> [http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org](http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

---

<div class="post-metadata">

**Author:** ![Mason\_Wheeler](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/b9bd4f/32.png) [@Mason\_Wheeler](https://discourse.libsdl.org/u/Mason_Wheeler)\
**Post date:** [March 24, 2009, 1:31pm UTC](https://discourse.libsdl.org/t/critical-sdl-1-3-patch/16134/5 "2009-03-24T13:31:32Z")

</div>

You know, you’re probably right. _grumbles about crazy languages with two different ANDs_\>\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

> From: David Turner   
> Subject: Re: [SDL] Critical SDL 1.3 patch
> 
> Are you sure you don’t want & instead of && ?
