SDL_CreateTexture failing

I’m trying to call SDL_CreateTexture(0, 1 (streaming), 96, 96), but it fails inside GDI_CreateTexture at this call:
} else {
data->hbm =
CreateCompatibleBitmap(renderdata->window_hdc, texture->w,
texture->h);

CreateCompatibleBitmap returns NULL.

I’ve got a valid window and a valid renderer, but the first time I try to create a texture, it doesn’t create. The renderer was created with the following Delphi call:

SDL_CreateRenderer(FWindowID, 1, [sdlrPresentCopy]);

where FWindowID is a valid SDL window. Anyone have any idea waht’s going on?

In case it helps, here’s a dump of the Renderer and Texture state data from the debugger, right before the call:

  •    renderer    0x00230558 {ActivateRenderer=0x00000000 DisplayModeChanged=0x100a1420 CreateTexture=0x100a1560 ...}    SDL_Renderer *
      ActivateRenderer    0x00000000    int (SDL_Renderer *)*
      DisplayModeChanged    0x100a1420 GDI_DisplayModeChanged(SDL_Renderer *)    int (SDL_Renderer *)*
      CreateTexture    0x100a1560 GDI_CreateTexture(SDL_Renderer *, SDL_Texture *)    int (SDL_Renderer *, SDL_Texture *)*
      QueryTexturePixels    0x100a18f0 GDI_QueryTexturePixels(SDL_Renderer *, SDL_Texture *, void * *, int *)    int (SDL_Renderer *, SDL_Texture *, void * *, int *)*
      SetTexturePalette    0x100a1940 GDI_SetTexturePalette(SDL_Renderer *, SDL_Texture *, const SDL_Color *, int, int)    int (SDL_Renderer *, SDL_Texture *, const SDL_Color *, int, int)*
      GetTexturePalette    0x100a1a20 GDI_GetTexturePalette(SDL_Renderer *, SDL_Texture *, SDL_Color *, int, int)    int (SDL_Renderer *, SDL_Texture *, SDL_Color *, int, int)*
      SetTextureColorMod    0x00000000    int (SDL_Renderer *, SDL_Texture *)*
      SetTextureAlphaMod    0x100a1af0 GDI_SetTextureAlphaMod(SDL_Renderer *, SDL_Texture *)    int (SDL_Renderer *, SDL_Texture *)*
      SetTextureBlendMode    0x100a1b00 GDI_SetTextureBlendMode(SDL_Renderer *, SDL_Texture *)    int (SDL_Renderer *, SDL_Texture *)*
      SetTextureScaleMode    0x100a1c80 GDI_SetTextureScaleMode(SDL_Renderer *, SDL_Texture *)    int (SDL_Renderer *, SDL_Texture *)*
      UpdateTexture    0x100a1cf0 GDI_UpdateTexture(SDL_Renderer *, SDL_Texture *, const SDL_Rect *, const void *, int)    int (SDL_Renderer *, SDL_Texture *, const SDL_Rect *, const void *, int)*
      LockTexture    0x100a1fe0 GDI_LockTexture(SDL_Renderer *, SDL_Texture *, const SDL_Rect *, int, void * *, int *)    int (SDL_Renderer *, SDL_Texture *, const SDL_Rect *, int, void * *, int *)*
      UnlockTexture    0x100a2080 GDI_UnlockTexture(SDL_Renderer *, SDL_Texture *)    void (SDL_Renderer *, SDL_Texture *)*
      DirtyTexture    0x00000000    void (SDL_Renderer *, SDL_Texture *, int, const SDL_Rect *)*
      SetDrawColor    0x00000000    int (SDL_Renderer *)*
      SetDrawBlendMode    0x100a20c0 GDI_SetDrawBlendMode(SDL_Renderer *)    int (SDL_Renderer *)*
      RenderPoint    0x100a2100 GDI_RenderPoint(SDL_Renderer *, int, int)    int (SDL_Renderer *, int, int)*
      RenderLine    0x100a2190 GDI_RenderLine(SDL_Renderer *, int, int, int, int)    int (SDL_Renderer *, int, int, int, int)*
      RenderFill    0x100a22c0 GDI_RenderFill(SDL_Renderer *, const SDL_Rect *)    int (SDL_Renderer *, const SDL_Rect *)*
      RenderCopy    0x100a23b0 GDI_RenderCopy(SDL_Renderer *, SDL_Texture *, const SDL_Rect *, const SDL_Rect *)    int (SDL_Renderer *, SDL_Texture *, const SDL_Rect *, const SDL_Rect *)*
      RenderPresent    0x100a25a0 GDI_RenderPresent(SDL_Renderer *)    void (SDL_Renderer *)*
      DestroyTexture    0x100a26c0 GDI_DestroyTexture(SDL_Renderer *, SDL_Texture *)    void (SDL_Renderer *, SDL_Texture *)*
      DestroyRenderer    0x100a2740 GDI_DestroyRenderer(SDL_Renderer *)    void (SDL_Renderer *)*
    
  •    info    {name=0x100ec550 "gdi" flags=66 mod_modes=2 ...}    SDL_RendererInfo
    
  •    name    0x100ec550 "gdi"    const char *
      flags    66    unsigned int
      mod_modes    2    unsigned int
      blend_modes    1    unsigned int
      scale_modes    1    unsigned int
      num_texture_formats    14    unsigned int
    
  •    texture_formats    0x002305cc    unsigned int [20]
      [0]    2197817345    unsigned int
      [1]    2232618754    unsigned int
      [2]    2232750082    unsigned int
      [3]    2249594884    unsigned int
      [4]    2253789188    unsigned int
      [5]    2251694084    unsigned int
      [6]    2252742660    unsigned int
      [7]    2255888388    unsigned int
      [8]    2256936964    unsigned int
      [9]    842094169    unsigned int
      [10]    1448433993    unsigned int
      [11]    844715353    unsigned int
      [12]    1498831189    unsigned int
      [13]    1431918169    unsigned int
      [14]    0    unsigned int
      [15]    0    unsigned int
      [16]    0    unsigned int
      [17]    0    unsigned int
      [18]    0    unsigned int
      [19]    0    unsigned int
      max_texture_width    0    int
      max_texture_height    0    int
      window    1    unsigned int
      r    0    unsigned char
      g    0    unsigned char
      b    0    unsigned char
      a    0    unsigned char
      blendMode    0    int
      driverdata    0x002310a0    void *
    
  •    texture    0x00231db8 {id=2 format=0 access=1 ...}    SDL_Texture *
      id    2    unsigned int
      format    0    unsigned int
      access    1    int
      w    96    int
      h    96    int
      modMode    0    int
      blendMode    0    int
      scaleMode    0    int
      r    255 '?'    unsigned char
      g    255 '?'    unsigned char
      b    255 '?'    unsigned char
      a    255 '?'    unsigned char
    
  •    renderer    0x00230558 {ActivateRenderer=0x00000000 DisplayModeChanged=0x100a1420 CreateTexture=0x100a1560 ...}    SDL_Renderer *
      driverdata    0x00231df0    void *
    
  •    next    0x00000000 {id=??? format=??? access=??? ...}    SDL_Texture *

Well, one interesting thing to note is that this code path is only
supposed to be active when not requesting streaming access:

if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING
    || texture->format != display->current_mode.format) {
....
} else {
    data->hbm =
        CreateCompatibleBitmap(renderdata->window_hdc, texture->w,

Are you doing anything interesting like using a foreign window? Can
you create a small example case?

I didn’t even know “streaming access” was relevant to GDI :OOn Tue, Mar 24, 2009 at 7:01 PM, Mason Wheeler wrote:

I’m trying to call SDL_CreateTexture(0, 1 (streaming), 96, 96), but it fails inside GDI_CreateTexture at this call:
? ?} else {
? ? ? ?data->hbm =
? ? ? ? ? ?CreateCompatibleBitmap(renderdata->window_hdc, texture->w,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? texture->h);

CreateCompatibleBitmap returns NULL.


http://codebad.com/

Oops! Wrong call! Sorry, it’s

    data->hbm =
        CreateDIBSection(renderdata->memory_hdc, bmi, DIB_RGB_COLORS,
                         &data->pixels, NULL, 0);

Good catch!

And yes, I have a small, simple test case. If you have a copy of Delphi, you can even test it out for yourself. (Unfortunately, it involves a custom component, which won’t work with the free Turbo Delphi version.) :frowning:

And it is using a foreign window, but the window and renderer have both been created correctly and it’s possible to draw to the window with SDL_RenderFill, so I doubt that’s the problem.>----- Original Message ----

From: Donny Viszneki <donny.viszneki at gmail.com>
Subject: Re: [SDL] SDL_CreateTexture failing

On Tue, Mar 24, 2009 at 7:01 PM, Mason Wheeler <@Mason_Wheeler> wrote:

I’m trying to call SDL_CreateTexture(0, 1 (streaming), 96, 96), but it fails inside GDI_CreateTexture at this call:
} else {
data->hbm =
CreateCompatibleBitmap(renderdata->window_hdc, texture->w,
texture->h);

CreateCompatibleBitmap returns NULL.

Well, one interesting thing to note is that this code path is only
supposed to be active when not requesting streaming access:

Are you doing anything interesting like using a foreign window? Can
you create a small example case?

I didn’t even know “streaming access” was relevant to GDI :open_mouth:

Out of curiosity, what is your SDL display mode?–
http://codebad.com/

SDL_GetCurrentDisplayMode returns:
format: 2249594884
w: 1920
h: 1080
refresh_rate: 60
driverdata: $290268

Which is basically just my screen resolution, unless that Format number means anything special. Is that what you’re looking for?>----- Original Message ----

From: Donny Viszneki <donny.viszneki at gmail.com>
Subject: Re: [SDL] SDL_CreateTexture failing

Out of curiosity, what is your SDL display mode?

This appears to mean this:

SDL_PIXELTYPE_PACKED32
SDL_BITMAPORDER_4321
SDL_PACKEDLAYOUT_8888
24 bits per pixel
4 bytes per pixel

Odd that 24 bits != 4 bytes

SDL_pixel.h is rather obtuse code. I don’t know why Sam didn’t use a
struct for this stuff! (Perhaps bitfields aren’t as portable as I’d
thought?)On Tue, Mar 24, 2009 at 9:23 PM, Mason Wheeler wrote:

format: 2249594884


http://codebad.com/

SDL_BITMAPORDER_4321 might also be SDL_PACKEDORDER_XRGB. Actually this
looks more reasonable. Thus the value SDL_PIXELFORMAT_RGB888 is what
we have. And now I understand why Sam didn’t use a struct – he wanted
to define all these enums, and I guess there’s no portable inline
struct value syntax?On Tue, Mar 24, 2009 at 10:39 PM, Donny Viszneki <@Donny_Viszneki> wrote:

SDL_PIXELTYPE_PACKED32
SDL_BITMAPORDER_4321
SDL_PACKEDLAYOUT_8888
24 bits per pixel
4 bytes per pixel

Odd that 24 bits != 4 bytes


http://codebad.com/