diff --git a/src/p_setup.c b/src/p_setup.c
index 5027bab0c6cdb93bdd5d4381fec15d150e6bdc5f..12f12e27acfb3ca26afb04604ea4eb77a9a60ce4 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -575,9 +575,9 @@ Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize)
 	strupr(levelflat->name);
 
 	/* If we can't find a flat, try looking for a texture! */
-	if (( flatnum = R_GetFlatNumForName(flatname) ) == LUMPERROR)
+	if (( flatnum = R_GetFlatNumForName(levelflat->name) ) == LUMPERROR)
 	{
-		if (( texturenum = R_CheckTextureNumForName(flatname) ) == -1)
+		if (( texturenum = R_CheckTextureNumForName(levelflat->name) ) == -1)
 		{
 			// check for REDWALL
 			if (( texturenum = R_CheckTextureNumForName("REDWALL") ) != -1)