Generalize function for texture path correction (Fixes #1779)