Skip to content

Commit

Permalink
Fix memory leak (google#6056)
Browse files Browse the repository at this point in the history
This change fixes google#6055
  • Loading branch information
romainguy authored Sep 9, 2022
1 parent 5e12821 commit eaa8606
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions samples/image_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static void createImageRenderable(Engine* engine, Scene* scene, App& app) {
app.scene.defaultTexture = texture;
}

static void loadImage(App& app, Engine* engine, Path filename) {
static void loadImage(App& app, Engine* engine, const Path& filename) {
if (app.scene.imageTexture) {
engine->destroy(app.scene.imageTexture);
app.scene.imageTexture = nullptr;
Expand Down Expand Up @@ -260,7 +260,8 @@ static void loadImage(App& app, Engine* engine, Path filename) {
size_t(w * h * channels * sizeof(float)),
channels == 3 ? Texture::Format::RGB : Texture::Format::RGBA,
Texture::Type::FLOAT,
freeCallback
freeCallback,
image
);

texture->setImage(*engine, 0, std::move(buffer));
Expand Down Expand Up @@ -351,10 +352,10 @@ int main(int argc, char** argv) {

if (app.showImage) {
Texture *texture = app.scene.imageTexture;
float srcWidth = texture->getWidth();
float srcHeight = texture->getHeight();
float dstWidth = view->getViewport().width;
float dstHeight = view->getViewport().height;
float srcWidth = (float) texture->getWidth();
float srcHeight = (float) texture->getHeight();
float dstWidth = (float) view->getViewport().width;
float dstHeight = (float) view->getViewport().height;

float srcRatio = srcWidth / srcHeight;
float dstRatio = dstWidth / dstHeight;
Expand Down

0 comments on commit eaa8606

Please sign in to comment.