probably you could do something like this:
tmax=512
test=createtexture(1024)
if texturewidth(test)=1024 then tmax=1024
freetexture test
test=createtexture(2048)
if texturewidth(test)=2048 then tmax=2048
freetexture test
tmax=512
test=createtexture(1024)
if texturewidth(test)=1024 then tmax=1024
freetexture test
test=createtexture(2048)
if texturewidth(test)=2048 then tmax=2048
freetexture test