start_buffer - 1Fr3aK2/Cub3d GitHub Wiki

📝 start_buffer

Initializes the map buffer by setting each element to NULL. This ensures that the buffer is empty before loading or processing the map data.

⚙️ Parameters

Parameter Type Description
data t_data * Pointer to the main data structure containing the map. Must be non-NULL.

🔁 Returns

Return value Description
void The function does not return any value. If data is NULL, the function simply returns without performing any action.

📖 Description

The start_buffer function iterates over the buffer array inside data->map and sets each element to NULL.
This prepares the buffer for subsequent operations, such as loading or parsing the map.

Steps performed by the function:

  1. Checks if the data pointer is NULL. If so, returns immediately.
  2. Iterates from index 0 to data->map.height (inclusive).
  3. Sets each element of data->map.buffer to NULL.

This prevents uninitialized memory from causing undefined behavior when accessing the map buffer later.

💡 Example Usage

t_data data;

// Initialize map buffer
start_buffer(&data);

// Now data.map.buffer elements are all set to NULL