Skip to content

Commit d762ee3

Browse files
committed
Add null check for SpriteFramesEditor's SpriteFrames
1 parent e585e6a commit d762ee3

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

editor/plugins/sprite_frames_editor_plugin.cpp

+109-1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ void SpriteFramesEditor::_sheet_scroll_input(const Ref<InputEvent> &p_event) {
280280
}
281281

282282
void SpriteFramesEditor::_sheet_add_frames() {
283+
if (frames.is_null()) {
284+
return;
285+
}
286+
283287
const Size2i frame_count = _get_frame_count();
284288
const Size2i frame_size = _get_frame_size();
285289
const Size2i offset = _get_offset();
@@ -688,6 +692,10 @@ void SpriteFramesEditor::_notification(int p_what) {
688692
}
689693

690694
void SpriteFramesEditor::_file_load_request(const Vector<String> &p_path, int p_at_pos) {
695+
if (frames.is_null()) {
696+
return;
697+
}
698+
691699
ERR_FAIL_COND(!frames->has_animation(edited_anim));
692700

693701
List<Ref<Texture2D>> resources;
@@ -747,6 +755,10 @@ Size2i SpriteFramesEditor::_get_separation() const {
747755
}
748756

749757
void SpriteFramesEditor::_load_pressed() {
758+
if (frames.is_null()) {
759+
return;
760+
}
761+
750762
ERR_FAIL_COND(!frames->has_animation(edited_anim));
751763
loading_scene = false;
752764

@@ -762,6 +774,10 @@ void SpriteFramesEditor::_load_pressed() {
762774
}
763775

764776
void SpriteFramesEditor::_paste_pressed() {
777+
if (frames.is_null()) {
778+
return;
779+
}
780+
765781
ERR_FAIL_COND(!frames->has_animation(edited_anim));
766782

767783
Ref<ClipboardSpriteFrames> clipboard_frames = EditorSettings::get_singleton()->get_resource_clipboard();
@@ -778,6 +794,10 @@ void SpriteFramesEditor::_paste_pressed() {
778794
}
779795

780796
void SpriteFramesEditor::_paste_frame_array(const Ref<ClipboardSpriteFrames> &p_clipboard_frames) {
797+
if (frames.is_null()) {
798+
return;
799+
}
800+
781801
if (p_clipboard_frames->frames.is_empty()) {
782802
return;
783803
}
@@ -805,6 +825,10 @@ void SpriteFramesEditor::_paste_frame_array(const Ref<ClipboardSpriteFrames> &p_
805825
}
806826

807827
void SpriteFramesEditor::_paste_texture(const Ref<Texture2D> &p_texture) {
828+
if (frames.is_null()) {
829+
return;
830+
}
831+
808832
float duration = 1.0;
809833

810834
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
@@ -821,6 +845,10 @@ void SpriteFramesEditor::_paste_texture(const Ref<Texture2D> &p_texture) {
821845
}
822846

823847
void SpriteFramesEditor::_copy_pressed() {
848+
if (frames.is_null()) {
849+
return;
850+
}
851+
824852
ERR_FAIL_COND(!frames->has_animation(edited_anim));
825853

826854
Vector<int> selected_items = frame_list->get_selected_items();
@@ -847,6 +875,10 @@ void SpriteFramesEditor::_copy_pressed() {
847875
}
848876

849877
void SpriteFramesEditor::_empty_pressed() {
878+
if (frames.is_null()) {
879+
return;
880+
}
881+
850882
ERR_FAIL_COND(!frames->has_animation(edited_anim));
851883

852884
int from = -1;
@@ -872,6 +904,10 @@ void SpriteFramesEditor::_empty_pressed() {
872904
}
873905

874906
void SpriteFramesEditor::_empty2_pressed() {
907+
if (frames.is_null()) {
908+
return;
909+
}
910+
875911
ERR_FAIL_COND(!frames->has_animation(edited_anim));
876912

877913
int from = -1;
@@ -897,6 +933,10 @@ void SpriteFramesEditor::_empty2_pressed() {
897933
}
898934

899935
void SpriteFramesEditor::_up_pressed() {
936+
if (frames.is_null()) {
937+
return;
938+
}
939+
900940
ERR_FAIL_COND(!frames->has_animation(edited_anim));
901941

902942
Vector<int> selected_items = frame_list->get_selected_items();
@@ -943,6 +983,10 @@ void SpriteFramesEditor::_up_pressed() {
943983
}
944984

945985
void SpriteFramesEditor::_down_pressed() {
986+
if (frames.is_null()) {
987+
return;
988+
}
989+
946990
ERR_FAIL_COND(!frames->has_animation(edited_anim));
947991

948992
Vector<int> selected_items = frame_list->get_selected_items();
@@ -989,6 +1033,10 @@ void SpriteFramesEditor::_down_pressed() {
9891033
}
9901034

9911035
void SpriteFramesEditor::_delete_pressed() {
1036+
if (frames.is_null()) {
1037+
return;
1038+
}
1039+
9921040
ERR_FAIL_COND(!frames->has_animation(edited_anim));
9931041

9941042
Vector<int> selected_items = frame_list->get_selected_items();
@@ -1038,7 +1086,7 @@ void SpriteFramesEditor::_sync_animation() {
10381086
}
10391087

10401088
void SpriteFramesEditor::_select_animation(const String &p_name, bool p_update_node) {
1041-
if (frames.is_null() || !frames->has_animation(p_name)) {
1089+
if (!frames->has_animation(p_name)) {
10421090
return;
10431091
}
10441092
edited_anim = p_name;
@@ -1081,6 +1129,10 @@ static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFr
10811129
}
10821130

10831131
void SpriteFramesEditor::_animation_name_edited() {
1132+
if (frames.is_null()) {
1133+
return;
1134+
}
1135+
10841136
if (updating) {
10851137
return;
10861138
}
@@ -1134,6 +1186,10 @@ void SpriteFramesEditor::_animation_name_edited() {
11341186
}
11351187

11361188
void SpriteFramesEditor::_rename_node_animation(EditorUndoRedoManager *undo_redo, bool is_undo, const String &p_filter, const String &p_new_animation, const String &p_new_autoplay) {
1189+
if (frames.is_null()) {
1190+
return;
1191+
}
1192+
11371193
List<Node *> nodes;
11381194
_find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(), &nodes, Ref<SpriteFrames>(frames));
11391195

@@ -1188,6 +1244,10 @@ void SpriteFramesEditor::_animation_add() {
11881244
}
11891245

11901246
void SpriteFramesEditor::_animation_duplicate() {
1247+
if (frames.is_null()) {
1248+
return;
1249+
}
1250+
11911251
if (updating) {
11921252
return;
11931253
}
@@ -1223,6 +1283,10 @@ void SpriteFramesEditor::_animation_duplicate() {
12231283
}
12241284

12251285
void SpriteFramesEditor::_animation_remove() {
1286+
if (frames.is_null()) {
1287+
return;
1288+
}
1289+
12261290
if (updating) {
12271291
return;
12281292
}
@@ -1236,6 +1300,10 @@ void SpriteFramesEditor::_animation_remove() {
12361300
}
12371301

12381302
void SpriteFramesEditor::_animation_remove_confirmed() {
1303+
if (frames.is_null()) {
1304+
return;
1305+
}
1306+
12391307
StringName new_edited;
12401308
List<StringName> anim_names;
12411309
frames->get_animation_list(&anim_names);
@@ -1276,6 +1344,10 @@ void SpriteFramesEditor::_animation_search_text_changed(const String &p_text) {
12761344
}
12771345

12781346
void SpriteFramesEditor::_animation_loop_changed() {
1347+
if (frames.is_null()) {
1348+
return;
1349+
}
1350+
12791351
if (updating) {
12801352
return;
12811353
}
@@ -1294,6 +1366,10 @@ void SpriteFramesEditor::_animation_speed_resized() {
12941366
}
12951367

12961368
void SpriteFramesEditor::_animation_speed_changed(double p_value) {
1369+
if (frames.is_null()) {
1370+
return;
1371+
}
1372+
12971373
if (updating) {
12981374
return;
12991375
}
@@ -1308,6 +1384,10 @@ void SpriteFramesEditor::_animation_speed_changed(double p_value) {
13081384
}
13091385

13101386
void SpriteFramesEditor::_frame_list_gui_input(const Ref<InputEvent> &p_event) {
1387+
if (frames.is_null()) {
1388+
return;
1389+
}
1390+
13111391
const Ref<InputEventMouseButton> mb = p_event;
13121392

13131393
if (mb.is_valid()) {
@@ -1342,6 +1422,10 @@ void SpriteFramesEditor::_frame_list_gui_input(const Ref<InputEvent> &p_event) {
13421422
}
13431423

13441424
void SpriteFramesEditor::_menu_selected(int p_id) {
1425+
if (frames.is_null()) {
1426+
return;
1427+
}
1428+
13451429
switch (p_id) {
13461430
case MENU_SHOW_IN_FILESYSTEM: {
13471431
Ref<Texture2D> frame_texture = frames->get_frame_texture(edited_anim, right_clicked_frame);
@@ -1359,6 +1443,10 @@ void SpriteFramesEditor::_menu_selected(int p_id) {
13591443
}
13601444

13611445
void SpriteFramesEditor::_frame_list_item_selected(int p_index, bool p_selected) {
1446+
if (frames.is_null()) {
1447+
return;
1448+
}
1449+
13621450
if (updating) {
13631451
return;
13641452
}
@@ -1374,6 +1462,10 @@ void SpriteFramesEditor::_frame_list_item_selected(int p_index, bool p_selected)
13741462
}
13751463

13761464
void SpriteFramesEditor::_frame_duration_changed(double p_value) {
1465+
if (frames.is_null()) {
1466+
return;
1467+
}
1468+
13771469
if (updating) {
13781470
return;
13791471
}
@@ -1399,6 +1491,10 @@ void SpriteFramesEditor::_frame_duration_changed(double p_value) {
13991491
}
14001492

14011493
void SpriteFramesEditor::_zoom_in() {
1494+
if (frames.is_null()) {
1495+
return;
1496+
}
1497+
14021498
// Do not zoom in or out with no visible frames
14031499
if (frames->get_frame_count(edited_anim) <= 0) {
14041500
return;
@@ -1412,6 +1508,10 @@ void SpriteFramesEditor::_zoom_in() {
14121508
}
14131509

14141510
void SpriteFramesEditor::_zoom_out() {
1511+
if (frames.is_null()) {
1512+
return;
1513+
}
1514+
14151515
// Do not zoom in or out with no visible frames
14161516
if (frames->get_frame_count(edited_anim) <= 0) {
14171517
return;
@@ -1645,6 +1745,10 @@ Ref<SpriteFrames> SpriteFramesEditor::get_sprite_frames() const {
16451745
}
16461746

16471747
Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
1748+
if (frames.is_null()) {
1749+
return false;
1750+
}
1751+
16481752
if (read_only) {
16491753
return false;
16501754
}
@@ -1718,6 +1822,10 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
17181822
}
17191823

17201824
void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
1825+
if (frames.is_null()) {
1826+
return;
1827+
}
1828+
17211829
if (!can_drop_data_fw(p_point, p_data, p_from)) {
17221830
return;
17231831
}

0 commit comments

Comments
 (0)