Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] error: invalid use of undefined type 'struct sfTexture'  (Read 9456 times)

0 Members and 1 Guest are viewing this topic.

DragonDePlatino

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Hi! I just picked up C and CSFML and I'm having some issues loading textures. My compiler is telling me that sfTexture is an incomplete type. The error in question:

Code: [Select]
||=== Build: Release in Crucis (compiler: GNU GCC Compiler) ===|
C:\Users\Platino\Documents\C\Crucis\src\window.c||In function 'loadTextures':|
C:\Users\Platino\Documents\C\Crucis\src\window.c|113|error: invalid use of undefined type 'struct sfTexture'|
C:\Users\Platino\Documents\C\Crucis\src\window.c|113|error: dereferencing pointer to incomplete type|
C:\Users\Platino\Documents\C\Crucis\src\window.c|114|error: invalid use of undefined type 'struct sfTexture'|
C:\Users\Platino\Documents\C\Crucis\src\window.c|114|error: dereferencing pointer to incomplete type|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

From what I understand, there is a declaration but no implementation of sfTexture? I'm confused as to why this is an issue. I've been using sfRenderWindow, sfRectangleShape and sfVertexArray from the same header with no problems. Am I doing something wrong? Here is the simplified code from window.c:

Code: [Select]
sfTexture* textures;
int texturenum = 2;

void loadTexture(void)
{
textures = malloc(sizeof(sfTexture*) * texturenum);
memset(textures, 0, sizeof(sfTexture*) * texturenum);

const char* filepath = "../img/tiles.png";
textures[0] = sfTexture_createFromFile(filepath, NULL); // Line 113

if(textures[0] == NULL) // Line 114
ERROR("Failed to load texture: ", filepath);
}

There's a lot going on with loading filenames from JSON and such, but I've triple-checked that's working correctly. Have I not correctly installed CSFML?
« Last Edit: October 02, 2016, 03:43:39 pm by DragonDePlatino »

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: error: invalid use of undefined type 'struct sfTexture'
« Reply #1 on: October 02, 2016, 07:46:08 am »
textures is a pointer to a sfTexture.

When you use array indexing with a pointer, it also dereferences the pointer after indexing, not giving you a pointer to a sfTexture, but a sfTexture value, which is kept hidden in the CSFML API. CSFML is designed to not reveal the internals of the structs it uses.

You need to make textures a pointer to a sfTexture pointer (ie: double pointer).

DragonDePlatino

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: error: invalid use of undefined type 'struct sfTexture'
« Reply #2 on: October 02, 2016, 03:43:10 pm »
Ah...pointers to pointers! I'm new to C so this is something I have not encountered yet. Thanks for the help.

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: [SOLVED] error: invalid use of undefined type 'struct sfTexture'
« Reply #3 on: October 02, 2016, 09:55:29 pm »
No problem. Just remember that you'll need to free each individual sfTexture* and then the sfTexture** afterwards when/if you're done with it.