My advice to you was this:
Meaning you should check img before allowing that triple for () {}
loop.
Also, this is an “infinite” loop block while (img) {
Given there’s nothing inside that block which can mutate variable img to “falsy”, it’s gonna repeat itself ad infinitum once it starts!