Repository: godotengine/godot
File: editor/plugins/tiles/atlas_merging_dialog.cpp (C++)

Code before:
#include "atlas_merging_dialog.h"

#include "editor/editor_properties_vector.h"
#include "editor/editor_scale.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_file_dialog.h"
#include "scene/gui/control.h"
#include "scene/gui/split_container.h"
#include "scene/resources/image_texture.h"

void AtlasMergingDialog::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
	_set(p_property, p_value);
}

void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atlas_sources, int p_max_columns) {
	merged.instantiate();
	merged_mapping.clear();

	if (p_atlas_sources.size() >= 2) {
		Ref<Image> output_image = Image::create_empty(1, 1, false, Image::FORMAT_RGBA8);

		// Compute the new texture region size.
		Vector2i new_texture_region_size;
		for (int source_index = 0; source_index < p_atlas_sources.size(); source_index++) {
			Ref<TileSetAtlasSource> atlas_source = p_atlas_sources[source_index];
			new_texture_region_size = new_texture_region_size.max(atlas_source->get_texture_region_size());
		}

		// Generate the new texture.
		Vector2i atlas_offset;
		int line_height = 0;
		for (int source_index = 0; source_index < p_atlas_sources.size(); source_index++) {
			Ref<TileSetAtlasSource> atlas_source = p_atlas_sources[source_index];
			Ref<Image> input_image = atlas_source->get_texture()->get_image();
			if (input_image->get_format() != Image::FORMAT_RGBA8) {
				input_image->convert(Image::FORMAT_RGBA8);
			}
			merged_mapping.push_back(HashMap<Vector2i, Vector2i>());

			// Layout the tiles.
			Vector2i atlas_size;

			for (int tile_index = 0; tile_index < atlas_source->get_tiles_count(); tile_index++) {
				Vector2i tile_id = atlas_source->get_tile_id(tile_index);
				atlas_size = atlas_size.max(tile_id + atlas_source->get_tile_size_in_atlas(tile_id));

				Rect2i new_tile_rect_in_atlas = Rect2i(atlas_offset + tile_id, atlas_source->get_tile_size_in_atlas(tile_id));

				// Copy the texture.
				for (int frame = 0; frame < atlas_source->get_tile_animation_frames_count(tile_id); frame++) {
					Rect2i src_rect = atlas_source->get_tile_texture_region(tile_id, frame);

Review comment (suggestion):
```suggestion
			new_texture_region_size = new_texture_region_size.max(p_atlas_sources[source_index]->get_texture_region_size());
```

Code after:
#include "atlas_merging_dialog.h"

#include "editor/editor_properties_vector.h"
#include "editor/editor_scale.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/gui/editor_file_dialog.h"
#include "scene/gui/control.h"
#include "scene/gui/split_container.h"
#include "scene/resources/image_texture.h"

void AtlasMergingDialog::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
	_set(p_property, p_value);
}

void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atlas_sources, int p_max_columns) {
	merged.instantiate();
	merged_mapping.clear();

	if (p_atlas_sources.size() >= 2) {
		Ref<Image> output_image = Image::create_empty(1, 1, false, Image::FORMAT_RGBA8);

		// Compute the new texture region size.
		Vector2i new_texture_region_size;
		for (int source_index = 0; source_index < p_atlas_sources.size(); source_index++) {
			const Ref<TileSetAtlasSource> &atlas_source = p_atlas_sources[source_index];
			new_texture_region_size = new_texture_region_size.max(atlas_source->get_texture_region_size());
		}

		// Generate the new texture.
		Vector2i atlas_offset;
		int line_height = 0;
		for (int source_index = 0; source_index < p_atlas_sources.size(); source_index++) {
			const Ref<TileSetAtlasSource> &atlas_source = p_atlas_sources[source_index];
			Ref<Image> input_image = atlas_source->get_texture()->get_image();
			if (input_image->get_format() != Image::FORMAT_RGBA8) {
				input_image->convert(Image::FORMAT_RGBA8);
			}
			merged_mapping.push_back(HashMap<Vector2i, Vector2i>());

			// Layout the tiles.
			Vector2i atlas_size;

			for (int tile_index = 0; tile_index < atlas_source->get_tiles_count(); tile_index++) {
				Vector2i tile_id = atlas_source->get_tile_id(tile_index);
				atlas_size = atlas_size.max(tile_id + atlas_source->get_tile_size_in_atlas(tile_id));

				Rect2i new_tile_rect_in_atlas = Rect2i(atlas_offset + tile_id, atlas_source->get_tile_size_in_atlas(tile_id));

				// Copy the texture.
				for (int frame = 0; frame < atlas_source->get_tile_animation_frames_count(tile_id); frame++) {
					Rect2i src_rect = atlas_source->get_tile_texture_region(tile_id, frame);