Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Connecting" SDL_Surface to shared_ptr

I'd like to know how can I connect SDL_Surface* with shared_ptr?
I need to call SDL_FreeSurface(SDL_Surface*) before I delete SDL_Surface. How can I "modify deletion process" in shared_ptr?

like image 843
fex Avatar asked Apr 03 '12 21:04

fex


1 Answers

Just pass SDL_FreeSurface to the constructor:

std::shared_ptr<SDL_Surface> shared_surf(SDL_LoadBMP("foo.bmp"), SDL_FreeSurface);

Just be sure you don't do this with the pointer returned by SDL_SetVideoMode or SDL_GetVideoSurface.

like image 200
Benjamin Lindley Avatar answered Sep 18 '22 02:09

Benjamin Lindley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!