jeremyletang / rust-sfml

SFML bindings for Rust
Other
639 stars 88 forks source link

Ported `sf::Context::getFunction()` #321

Closed truenotzero closed 11 months ago

truenotzero commented 11 months ago

Ported sf::Context::getFunction():

Possible changes: Change Context::get_function()'s signature, as it currently is: unsafe fn(&CStr) -> *const std::ffi::c_void

crumblingstatue commented 11 months ago

Hi, thank you for your pull request!

On my system, this produces the following error during building CSFML:

CSFML/src/Window/Window.cpp: In function ‘void* sfContext_getFunction(const char*)’:
CSFML/src/Window/Window.cpp:152:36: error: invalid conversion from ‘sf::GlFunctionPointer’ {aka ‘void (*)()’} to ‘void*’ [-fpermissive]
  152 |     return sf::Context::getFunction(name);
      |            ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
      |                                    |
      |                                    sf::GlFunctionPointer {aka void (*)()}
crumblingstatue commented 11 months ago

Returning sf::GlFunctionPointer seems to solve it, but not sure if it has any caveats.

truenotzero commented 11 months ago

You're absolutely right! That's a bad function declaration, which causes an implicit cast from void(*)() to void* (which is illegal in C++). Weird that my compiler didn't even warn about it...

I updated the code with your suggestion.

crumblingstatue commented 11 months ago

Thank you for your contribution!