Procedural Generation: How To Keep Player out of Walls

So I put together a procedural generated map, and when I click it, the map randomly changes. What it does is it loops through the plane and randomly generates a mesh depending on the square’s placement compared to randomfillpercent. If the map coordinate is marked 1, it’s a wall, and if it’s 0, its open space. I’m having an issue where if I click the map, the player sphere ends up inside the randomly generated wall. I want to make it so if the player’s position is equal to a map coordinate that’s a wall, then move it down the map until it reaches open space. Unfortunately, I keep getting null reference errors. I anyone could give me some ideas, I would appreciate it. Here’s my variables and my RandomFillMap function. I’m not showing the whole code. If there’s something you need to see, let me know. Thank you.

public class MapGeneratorCave : MonoBehaviour {

public int width;
public int height;

public string seed;
public bool useRandomSeed;
public GameObject player;
int[,] playerPosition;

[Range(0, 100)]
public int randomFillPercent;

int[,] map;

void Start()
{
    GenerateMap();
}

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
        GenerateMap();
    }
}

void GenerateMap()
{
    map = new int[width, height];
    RandomFillMap();

    for (int i = 0; i < 5; i++)
    {
        SmoothMap();
    }

    ProcessMap();

    int borderSize = 1;
    int[,] borderedMap = new int[width + borderSize * 2, height + borderSize * 2];

    for (int x = 0; x < borderedMap.GetLength(0); x++)
    {
        for (int y = 0; y < borderedMap.GetLength(1); y++)
        {
            if (x >= borderSize && x < width + borderSize && y >= borderSize && y < height + borderSize)
            {
                borderedMap[x, y] = map[x - borderSize, y - borderSize];
            }
            else
            {
                borderedMap[x, y] = 1;
            }
        }
    }

    MeshGenerator meshGen = GetComponent<MeshGenerator>();
    meshGen.GenerateMesh(borderedMap, 1);
}



 void RandomFillMap()
{
    int playerX = (int)player.transform.position.x;
    int playerY = (int)player.transform.position.y;

    if (useRandomSeed)
    {
        seed = Time.time.ToString();
    }

    System.Random pseudoRandom = new System.Random(seed.GetHashCode());

    for (int x = 0; x < width; x++)
    {
        for (int y = 0; y < height; y++)
        {
            if (x == 0 || x == width - 1 || y == 0 || y == height - 1)
            {
                map[x, y] = 1;
            }
            else
            {
                map[x, y] = (pseudoRandom.Next(0, 100) < randomFillPercent) ? 1 : 0;
            }
            if (playerPosition[playerX, playerY] == map[x, y] && map[x, y] == 1) 
            {
                playerPosition[playerX, playerY] = map[x, y - 1];
            }
        }
    }
}

From what I can tell, you need to initialize playerPosition (the multidimensional array).