The issue is likely that when you set the texture in the initialization list, the texture has no size and thus the texture rect of the sprite will also be set to no size. Then when you load the texture, you never adjust the texture rect and thus nothing is shown.
The
sprite.setTexture call isn't necessary, as you've already set the texture by passing it to the sprite, but what you want to do is call
sprite.setTextureRect(IntRect({0, 0}, Vector2i(texture.getSize()))) to match the texture size.
MyDrawable::MyDrawable() : sprite(texture) {
if (!texture.loadFromFile("image.png")) {
std::cerr << "Error loading texture!" << std::endl;
} else {
sprite.setTextureRect(sf::IntRect({0, 0}, sf::Vector2i(texture.getSize())));
}
}
Or if you're fine with handling exceptions, you could also do:
MyDrawable::MyDrawable() : texture("image.png"), sprite(texture) {
}