Issue with tile texture function

Hey guys. All I wanted to do was create a function to take an instance of the texture class I created and tile it. Simple enough. Weirdly though, it only works with certain textures. Attached is the partial code of my texture class (the tileImage function), and the partial code in my main file (where you put code to render the textures).

No matter what I do, text_babyPixel (which is just a 1x1 white pixel I was planning on using for backgrounds) will just not display and the program crashes. But, text_rightGrid and text_leftGrid (which are just like a chess board pattern) both tile correctly when ran individually. However, when the program is run and text_rightGrid and text_leftGrid’s tileImage functions are called, they both are displayed, and the specified y coordinates are fine, but for some reason the x coordinates are weird. They get bunched up together either on the left side or right side of the screen. Any idea. Thanks!

//Beginning of Renderer-----------------------------------------------------------------------------------------

			//updating the surface
			//SDL_UpdateWindowSurface(window);

			//for textures
			//Clear Screen
			SDL_RenderClear(window.getRenderer());

		//Beginning of rendering textures---------------------------------------------------------------------------------------------------------

			text_rightGrid.tileImage((window.getW() - text_rightGrid.getW()), 0, 1, (window.getH() / text_leftGrid.getH()) + 1);
			//text_leftGrid.tileImage(0, 0, 1, (window.getH() / text_leftGrid.getH()) + 1);
			//text_babyPixel.tileImage(0, 0, window.getW(), window.getH());

//Tile the texture
void texture::tileImage(int tempX, int tempY, int tempW, int tempH) {

/*

Later, after you finish the location class, implement code
so it gets the size of the location and automatically fills in the entire
location so you don't have to specify it.

*/

//if the texture hasn't been tiled
if (!hasTiled) {
	int tileWidth = w; // Width of each tile
	int tileHeight = h; // Height of each tile

	// Save the initial tiling dimensions
	int initialX = tempX;
	int initialY = tempY;
	int initialW = tempW;
	int initialH = tempH;

	for (int i = 0; i < initialH; i++) {
		for (int j = 0; j < initialW; j++) {
			// Create a new texture object for the current tile
			texture* tile = new texture(*this); // Copy constructor

			// Set the position for this tile
			tile->setX(initialX + j * tileWidth);
			tile->setY(initialY + i * tileHeight);

			// Add the tile to the rendering vector
			tile->displayImage(tile->getX(), tile->getY());
		}
	}

	// Set flag to true so the tiling won't run again.
	hasTiled = true;
}

//if the texture has been tiled
else {
	// If it has been tiled before, adjust the positions of the existing tiles
	int tileWidth = w; // Width of each tile
	int tileHeight = h; // Height of each tile

	for (int i = 0; i < tempH; i++) {
		for (int j = 0; j < tempW; j++) {
			// Get the tile by its position in the vector
			int tileIndex = i * tempW + j;
			if (tileIndex < textureDepth.size()) {
				texture* tile = textureDepth[tileIndex];

				// Set the new position for this tile
				tile->setX(tempX + j * tileWidth);
				tile->setY(tempY + i * tileHeight);
			}
		}
	}
}

}