Why did you change to a minus sign here?

& ~1 is the same as & 0xFFFFFFFE, that is, just chopping off the lowest bit, turning it into an even number.

&~-1 would be & ~0xFFFFFFFF  = & 0  which simply zeroes it out, which means that it's now ignoring scissor and region entirely, and your change to std::max below means that once again, all textures will be 512x512.

So in essence, you can replace everything in the else case with:

drawing_width = 512;
drawing_height = 512;

which we know isn't right.