CSFML icon indicating copy to clipboard operation
CSFML copied to clipboard

use non-throwing new operator to allocate memory for sfObj_create / sfObj_copy

Open ZXShady opened this issue 1 year ago • 0 comments

sfSound* sfSound_create(const sfSoundBuffer* buffer)
{
    assert(buffer);
    return new sfSound{sf::Sound(buffer->This), buffer}; 
// what would happen if new throws?
}

best to replace it with new(std::nothrow) which returns null on allocation failure. the copy can still fail and throw an exception!

C doesn't have exceptions and in general we should catch exceptions and translate them to error codes or let nothrow new do that for us.

ZXShady avatar Sep 17 '24 02:09 ZXShady