Repository: godotengine/godot
File: editor/scene/2d/tiles/tile_set_editor.cpp (C++)

Code before:

void TileSetEditor::_set_source_sort(int p_sort) {
	TilesEditorUtils::get_singleton()->set_sorting_option(p_sort);
	for (int i = 0; i != TilesEditorUtils::SOURCE_SORT_MAX; i++) {
		source_sort_button->get_popup()->set_item_checked(i, (i == (int)p_sort));
	}

	int old_selected = TileSet::INVALID_SOURCE;
	if (sources_list->get_current() >= 0) {
		int source_id = sources_list->get_item_metadata(sources_list->get_current());
		if (tile_set->has_source(source_id)) {
			old_selected = source_id;
		}
	}
	_update_sources_list(old_selected);

	if (!first_edit) {
		EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "tile_source_sort", p_sort);
	}
}

void TileSetEditor::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_THEME_CHANGED: {
			sources_delete_button->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
			sources_add_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
			source_sort_button->set_button_icon(get_editor_theme_icon(SNAME("Sort")));
			sources_advanced_menu_button->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
			missing_texture_texture = get_editor_theme_icon(SNAME("TileSet"));
			expanded_area->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("expand_panel"), SNAME("TileSetEditor")));
			_update_sources_list();
		} break;

		case NOTIFICATION_INTERNAL_PROCESS: {
			if (tile_set_changed_needs_update) {
				if (tile_set.is_valid()) {
					tile_set->set_edited(true);
				}

				read_only = false;
				if (tile_set.is_valid()) {
					read_only = EditorNode::get_singleton()->is_resource_read_only(tile_set);
				}

				_update_sources_list();
				_update_patterns_list();

				sources_add_button->set_disabled(read_only);
				sources_advanced_menu_button->set_disabled(read_only);
				source_sort_button->set_disabled(read_only);


Review comment (suggestion):
Looks like this needs to check if the tile_set is valid, it prints an error on startup `ERROR: Condition "tile_set.is_null()" is true. at: TileSetEditor::_update_patterns_list (editor/scene/2d/tiles/tile_set_editor.cpp:445)`

Code after:

void TileSetEditor::_set_source_sort(int p_sort) {
	TilesEditorUtils::get_singleton()->set_sorting_option(p_sort);
	for (int i = 0; i != TilesEditorUtils::SOURCE_SORT_MAX; i++) {
		source_sort_button->get_popup()->set_item_checked(i, (i == (int)p_sort));
	}

	int old_selected = TileSet::INVALID_SOURCE;
	if (sources_list->get_current() >= 0) {
		int source_id = sources_list->get_item_metadata(sources_list->get_current());
		if (tile_set->has_source(source_id)) {
			old_selected = source_id;
		}
	}
	_update_sources_list(old_selected);

	if (!first_edit) {
		EditorSettings::get_singleton()->set_project_metadata("editor_metadata", "tile_source_sort", p_sort);
	}
}

void TileSetEditor::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_TRANSLATION_CHANGED: {
			_update_sources_list();
			_update_patterns_list();
		} break;

		case NOTIFICATION_THEME_CHANGED: {
			sources_delete_button->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
			sources_add_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
			source_sort_button->set_button_icon(get_editor_theme_icon(SNAME("Sort")));
			sources_advanced_menu_button->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
			missing_texture_texture = get_editor_theme_icon(SNAME("TileSet"));
			expanded_area->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("expand_panel"), SNAME("TileSetEditor")));
			_update_sources_list();
		} break;

		case NOTIFICATION_INTERNAL_PROCESS: {
			if (tile_set_changed_needs_update) {
				if (tile_set.is_valid()) {
					tile_set->set_edited(true);
				}

				read_only = false;
				if (tile_set.is_valid()) {
					read_only = EditorNode::get_singleton()->is_resource_read_only(tile_set);
				}

				_update_sources_list();
				_update_patterns_list();