9

a day ago I installed an SDL2 library. It is not in Debian Wheezy yet, so I used configure, make, make install commands.

After all, when I try to use SDL_Texture, I get this error:

error: forward declaration of ‘SDL_Texture {aka struct SDL_Texture}’
invalid use of incomplete type ‘SDL_Texture {aka struct SDL_Texture}’

After looking for declaration, everything I found are these two lines in SDL_render.h:

struct SDL_Texture;
typedef struct SDL_Texture SDL_Texture; 

No definition at all. I think my installation is missing file SDL_sysrender.h. It is in source code I downloaded, but not in SDL2 include path.

Where should be the problem? Its necessary to use any flag for configure file? Thank you for help.

3
  • What headers are you including? It sounds like one of the SDL class headers has a forward declaration but the actual class header for that class isn't included somewhere and thus, you have an incomplete class definition. I don't know what would happen if you call a header file that isn't found, I would guess you'd get a linker error and not this error.
    – Chemistpp
    Sep 19, 2013 at 14:46
  • I am currently including only SDL_render.h. I will try use SDL.h and look what will happend
    – Lorin
    Sep 19, 2013 at 14:51
  • Even with a SDL.h the problem remains.
    – Lorin
    Sep 20, 2013 at 9:07

1 Answer 1

15

There's nothing wrong with your install. SDL_Texture is an opaque type by design (that is, designed to only be operated on by SDL2 internally), you can "pass it around" as a pointer, but you can't access the internals (or create a SDL_Texture yourself, for example by doing a malloc, because you don't know the size of the structure). If you stick to

SDL_Texture *blah;

pointers and pass them around to the SDL2 functions you should be fine.

SDL_sysrender.h is an internal header which, as you mentioned, actually defines SDL_Texture for internal consumption of the library.

5
  • 1
    Ah, my bad. How can I edit Texture or access its properties? For example when creating copy of already existing Texture?
    – Lorin
    Sep 20, 2013 at 15:10
  • I know about this one, but it does not provide a "renderer" info. I can not create a copy of given texture with the same renderer...
    – Lorin
    Sep 25, 2013 at 16:52
  • 1
    I mean deep copy (not just copy pointer but create another Texture with the same arguments)
    – Lorin
    Sep 25, 2013 at 17:00
  • 1
    Yeah, that's a gap in SDL2's API. It's actually redundant to ask for a renderer when operating on a SDL_Texture because internally the texture knows which render it belongs to (and there's actually internal check to verify that you don't mix them up). You can keep track of the renderer externally (most apps use just one renderer), or fill out a bug with SDL asking for a modification and stating the problem you are facing.
    – gabomdq
    Sep 25, 2013 at 23:51
  • This always seemed like a strange design choice to me anyway, at least in contrast with things like SDL_GLContext (AKA void*). After all, you can't dereference SDL_Window*, SDL_Texture*, etc. - the visible pointer led me to try to use shared_ptr/unique_ptr/etc. to remove the raw pointer and enforce correct memory management (and caused some very confusing errors.) Without knowing more about implementation hiding or SDL itself, it seems misleading to me. Are there other options? Why couldn't/wouldn't they expose defined structures to contain/hide these decl-only ones?
    – John P
    Aug 31, 2017 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.