Skip to content

Commit

Permalink
Merge pull request godotengine#18 from ramatakinc/bugfix/3.5-ad-edito…
Browse files Browse the repository at this point in the history
…r-crash

Fix crash in ad unit editor
  • Loading branch information
ellenhp authored Jul 14, 2023
2 parents 62e2741 + 28451f5 commit 5ab9f26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
30 changes: 24 additions & 6 deletions editor/ramatak/ramatak_settings_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ void RamatakSettingsAdUnitEditor::_bind_methods() {
Dictionary RamatakSettingsAdUnitEditor::get_ad_unit_config() const {
Dictionary ad_unit_config;
ERR_FAIL_COND_V_MSG(edits.size() != labels.size(), ad_unit_config, "Edits and labels size mismatch.");
ad_unit_config[_AD_UNIT_TYPE_KEY] = ad_unit_type_option_button->get_selected_metadata();
for (int i = 0; i < edits.size(); i++) {
ad_unit_config[plugins[i]] = edits[i]->get_text();
if (ad_unit_type_option_button != nullptr) {
ad_unit_config[_AD_UNIT_TYPE_KEY] = ad_unit_type_option_button->get_selected_metadata();
for (int i = 0; i < edits.size(); i++) {
ad_unit_config[plugins[i]] = edits[i]->get_text();
}
}
return ad_unit_config;
}
Expand Down Expand Up @@ -93,6 +95,10 @@ void RamatakSettingsAdUnitEditor::_ad_unit_edited(Variant p_arg) {

void RamatakSettingsAdUnitEditor::clear() {
ad_unit = "";
if (ad_unit_type_option_button) {
memdelete(ad_unit_type_option_button);
ad_unit_type_option_button = nullptr;
}
ERR_FAIL_COND_MSG(edits.size() != labels.size(), "Edits and labels size mismatch.");
for (int i = 0; i < edits.size(); i++) {
LineEdit *edit = edits[i];
Expand Down Expand Up @@ -177,6 +183,7 @@ void RamatakSettingsAdUnitSetEditor::_add_ad_unit() {
}

void RamatakSettingsAdUnitSetEditor::_save() {
print_verbose("Attempting to save ad unit settings.");
if (Error::OK != ProjectSettings::get_singleton()->save()) {
WARN_PRINT("Failed to save");
}
Expand All @@ -186,11 +193,22 @@ void RamatakSettingsAdUnitSetEditor::_remove_ad_unit() {
Dictionary ad_units_config = ProjectSettings::get_singleton()->get("ramatak/monetization/ad_units");
Vector<int> selected_items = edit_items_list->get_selected_items();
if (selected_items.size() > 0) {
int item_to_remove = selected_items.get(0);
// DEV_ASSERT(ad_unit_editor->get_ad_unit() != "");
ad_units_config.erase(ad_unit_editor->get_ad_unit());
edit_items_list->remove_item(selected_items.get(0));
ad_unit_editor->clear();
ad_unit_editor->set_disabled(true);
edit_items_list->remove_item(item_to_remove);
edit_items_list->unselect_all();
if (edit_items_list->get_item_count() > 0) {
int item_to_select = 0;
if (item_to_remove > 0) {
item_to_select = item_to_remove - 1;
}
edit_items_list->select(item_to_select);
String ad_unit = edit_items_list->get_item_text(item_to_select);
ad_unit_editor->set_ad_unit(ad_unit);
} else {
ad_unit_editor->clear();
}
}
ProjectSettings::get_singleton()->set("ramatak/monetization/ad_units", ad_units_config);
call_deferred("_save");
Expand Down
4 changes: 2 additions & 2 deletions editor/ramatak/ramatak_settings_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class Label;
class RamatakSettingsAdUnitEditor : public Control {
GDCLASS(RamatakSettingsAdUnitEditor, Control);

GridContainer *grid_container;
GridContainer *grid_container = nullptr;

OptionButton *ad_unit_type_option_button;
OptionButton *ad_unit_type_option_button = nullptr;
List<String> plugins;
List<Label *> labels;
List<LineEdit *> edits;
Expand Down

0 comments on commit 5ab9f26

Please sign in to comment.