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

Author Topic: CSFML-2 sfSprite_get* type issue  (Read 6257 times)

0 Members and 1 Guest are viewing this topic.

col

  • Newbie
  • *
  • Posts: 7
    • View Profile
CSFML-2 sfSprite_get* type issue
« on: March 21, 2013, 10:54:58 am »
Hiya,

I'm writing a wrapper for SFML-2 using the C headers and win32 gcc .libs. I have 90% of it done and functioning , but I have a problem with the set of sfSprite_get functions.

sfVector2f pos = sfSprite_getPosition(sprite);

( where 'sprite' is a valid const sfSprite* proved to be valid in that I can see and move it around the screen ) but the compiler complains with 'error: invalid initializer' and points to that line. My first thought was to use sfVector2f* which compiles but crashes when I try to access the variables of the sfVector2f.

Are there any thoughts on this?

Many thanks.
Dave.

edit: I should note that this happens with all of the sfSprite_get functions. Very strange.
« Last Edit: March 21, 2013, 11:02:27 am by col »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: CSFML-2 sfSprite_get* type issue
« Reply #1 on: March 21, 2013, 12:11:28 pm »
Don't forget that you can't declare variables in the middle of functions in C (unless you force C99 mode).
Laurent Gomila - SFML developer

col

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: CSFML-2 sfSprite_get* type issue
« Reply #2 on: March 21, 2013, 12:29:18 pm »
Hiya,

Thankyou for the prompt reply.
Yes, that is already set. The funny thing is I'm using the technique through the rest of the wrapper and it works ok. Its all of the sfSprite_get* functions except getRotation which returns a float that are causing this issue. The other 'types' are working ok. I imagine its a silly issue, but the I can't for the life of me think what it could be.

Many thanks.
Dave.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: CSFML-2 sfSprite_get* type issue
« Reply #3 on: March 21, 2013, 02:40:41 pm »
Are all the required headers included?

If so, come up with a complete and minimal example.
« Last Edit: March 21, 2013, 02:49:30 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

col

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: CSFML-2 sfSprite_get* type issue
« Reply #4 on: March 21, 2013, 07:46:35 pm »
Hiya,

I'm sure the headers are included properly. I get 'type not found' errors if I comment out the #include statements.

In the exact same file I have :-

// This works as expected
void bmx_sfText_getPosition(const sfText* text, sfVector2f* position) {
        *position = sfText_getPosition(text);
}
 
and further down in the same file I have :-

// This function works as expected
void bmx_sfSprite_setOrigin(const sfSprite* sprite, sfVector2f* origin) {
        sfSprite_setOrigin(sprite,*origin);
}

// This function gives me an error
void bmx_sfSprite_getPosition(const sfSprite* sprite,sfVector2f* position) {
        *position = sfSprite_getPosition(sprite);
}

All of the wrapper functions are in the one file which includes the other type functions and also the other sfSprite functions too which are confirmed to be working.

As a part of trying to hone in with whats happening if I do this inside the above function body :-

sfVector2f position;
position = sfSprite_getPosition(sprite);

then I get 'error: incompatible types when assigning to type 'sfVector2f' from type 'int''

as opposed to this:-

sfVector2f pos = sfSprite_getPosition(sprite);

which gives the error in the original post.
Are there any clues in there? How is it possible for the compiler to get an 'int' reference from anywhere or is this a default of some kind?

I can't really give a 'working' example of it in effect as this is a wrapper bindings for a different language and there is only this one 'C' file that gets imported into the other language.

Thanks for your help.
Dave.
« Last Edit: March 21, 2013, 08:13:24 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: CSFML-2 sfSprite_get* type issue
« Reply #5 on: March 21, 2013, 08:15:34 pm »
It really seems like you forget to include Sprite.h.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: CSFML-2 sfSprite_get* type issue
« Reply #6 on: March 21, 2013, 08:18:50 pm »
The int comes from the property of C, that not declared functions are assumed to return int. So yes, it really looks like sfSprite_getPosition() is not declared.

You should increase your compiler's warning level, then it also annotates other functions that are not declared, but still compile. Note that it is undefined behavior if the compiler's assumption about the declaration differs from the correct one.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

col

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: CSFML-2 sfSprite_get* type issue
« Reply #7 on: March 21, 2013, 08:49:52 pm »
Thankyou for the prompt help.

I knew it would be something silly! I was including the SFML/Graphics.h file which I assumed would include the sprite.h as it includes all of the other types header files in that directory. But alas the '#include <SFML/Sprite.h>' entry is missing from the list. Is that deliberate? I put the entry in myself and all the problems have gone.

I'll post back with links/references to the bindings wrapper when its complete.

Thank you again. Very helpful guys!
Dave.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: CSFML-2 sfSprite_get* type issue
« Reply #8 on: March 21, 2013, 09:51:56 pm »
It was fixed a long time ago.
Laurent Gomila - SFML developer

col

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: CSFML-2 sfSprite_get* type issue
« Reply #9 on: March 21, 2013, 11:17:32 pm »
I see. Does that mean I'm using old headers? I downloaded them from the Downloads section linked from the front page of this website.

Dave.

Edit: Is there a link or somewhere with information on other issues that I may run into that are already resolved? Or better still where I could get the latest version. Thanks.
« Last Edit: March 22, 2013, 01:37:26 am by col »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: CSFML-2 sfSprite_get* type issue
« Reply #10 on: March 22, 2013, 06:17:32 am »
You can get the latest CSFML version from GitHub:
https://github.com/SFML/CSFML
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

col

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: CSFML-2 sfSprite_get* type issue
« Reply #11 on: March 22, 2013, 12:49:00 pm »
Excellent, thankyou.

Now this has opened a whole new can of worms :o
I've spent the last few hours trying to compile the source. I've had all of the problems countless others have had ( fixed through searching this site for solutions ), and I still can't get it to compile using CMake. There seems the FindSFML.cmake is missing as it isnt in the CSFML github repo. Its in the SFML one but not the CSFML one.

There are problems after problems. Maybe I should/shouldn't have done it but I used the FindSFML.cmake from the CSFML repo. I then get more errors of not finding the SFML library files. I searched this site again and theres mention of them being in the lib folder. But it seems that things just arent happening for me, there is no lib folder under 'program files/sfml' or 'program files(86)/sfml'.

To be honest, spending all this time trying to get it to compile is distracting me from the original project of creating the wrapper bindings, and at this stage I concede defeat. So I'm asking for saviour, for a kind soul that has the latest github repo of the CSFML2 library built for use with MingW on Win32 who may also have a link of where I could download it.

Many thanks.
Dave.
« Last Edit: March 22, 2013, 12:52:09 pm by col »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: CSFML-2 sfSprite_get* type issue
« Reply #12 on: March 22, 2013, 02:02:32 pm »
It's not complicated ;)

1. Copy FindSFML.cmake where CMake can find it -- the easiest is to copy it directly to your CMake folder (under share/cmake-x.x/Modules)

2. Tell CMake where SFML is, by defining the SFML_ROOT variable (as explained in FindSFML.cmake) to the directory that contains your SFML "include" and "lib" directories. Note that you must have the static SFML libs, since CSFML links to them.

After that everything should compile out of the box.
Laurent Gomila - SFML developer

col

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: CSFML-2 sfSprite_get* type issue
« Reply #13 on: March 22, 2013, 08:52:43 pm »
You're right. It's not complicated when you know how   :D
Everything is built and working great now.

Thanks agian for your prompt help.

Dave.