examples: preventing undef behavior

Calling get() on a unique pointer after
it has been moved is the undefined behavior.
This commit is contained in:
Mira Grudzinska 2023-04-03 22:45:26 +02:00 committed by Hermet Park
parent d60a7bec7e
commit 9102f66948
2 changed files with 6 additions and 4 deletions

View file

@ -40,8 +40,9 @@ void tvgDrawCmds(tvg::Canvas* canvas)
cout << "The PNG file is not loaded correctly. Did you enable PNG Loader?" << endl; cout << "The PNG file is not loaded correctly. Did you enable PNG Loader?" << endl;
return; return;
} }
if (canvas->push(move(picture)) == tvg::Result::Success) { pPicture = picture.get();
pPicture = picture.get(); if (canvas->push(move(picture)) != tvg::Result::Success) {
pPicture = nullptr;
} }
} }

View file

@ -40,8 +40,9 @@ void tvgDrawCmds(tvg::Canvas* canvas)
cout << "The PNG file is not loaded correctly. Did you enable PNG Loader?" << endl; cout << "The PNG file is not loaded correctly. Did you enable PNG Loader?" << endl;
return; return;
} }
if (canvas->push(move(picture)) == tvg::Result::Success) { pPicture = picture.get();
pPicture = picture.get(); if (canvas->push(move(picture)) != tvg::Result::Success) {
pPicture = nullptr;
} }
} }