Skip to content

Add null check for SpriteFramesEditor's SpriteFrames #104830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

chocola-mint
Copy link
Contributor

@chocola-mint chocola-mint commented Mar 31, 2025

Fixes #104822

Adding missing null checks for frames seems to be more in-line with existing code, (see also: AnimationTrackEditor's animation.ptr() null checks) so this is the solution I ended up with.

@KoBeWi
Copy link
Member

KoBeWi commented Mar 31, 2025

Pretty sure there doesn't need to be a null check in every method 🤔 Some of the checks can't be probably reached.
From more obvious ones, _animation_selected(), _sync_animation() and can_drop_data_fw() do not need a check, because frames is not referenced there.

Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixes the crash, but looks like overkill to me.

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say we should at least consider the error being elsewhere first, or at least reduce the number of cases here, it feels very brute force to solve the problem this way

IMO, we should:

  • Establish that this is the place to fix this, and make sure there methods being called with frames.is_null() == true is correct
  • Establish which cases specifically need to be solved this way

This at the surface looks like solving the problem in the wrong place, at least without a deeper evaluation

In my experience adding null-checks, especially for states belonging to the object itself, is solving a symptom not a cause

@chocola-mint
Copy link
Contributor Author

Pretty sure there doesn't need to be a null check in every method 🤔 Some of the checks can't be probably reached.
From more obvious ones, _animation_selected(), _sync_animation() and can_drop_data_fw() do not need a check, because frames is not referenced there.

Got it. I've removed unnecessary null checks.

I'd say we should at least consider the error being elsewhere first, or at least reduce the number of cases here, it feels very brute force to solve the problem this way

While I can understand where you're coming from, IMO this is consistent with how AnimationTrackEditor handles the same issue. For example, here. (A lot of similar examples can be found in the same file)

The other solution I had in mind was to disconnect the signals causing the crashes when frames is set to null here, and connecting them when frames is set to a non-null value. Does that sound better to you?

@AThousandShips
Copy link
Member

This sounds fine, my main concern was with if the check should just be elsewhere

If this is caused by signals or other things like that I think it's fine to do things this way!

It's more a question of "is this the best way to solve this", if the other way would be convoluted messing with signals then this is fine

@KoBeWi
Copy link
Member

KoBeWi commented Mar 31, 2025

This particular crash is caused by the SpriteFrames editor getting hidden, which causes frames to become null and also the SpinBox to lose focus, which in turn emits the value_changed signal. It's just unfortunate order of events and probably can't be fixed in a better way.

We could keep the fix limited to this single case. That risks another crash being discovered elsewhere, but prevents having too many unnecessary checks.

@chocola-mint
Copy link
Contributor Author

This particular crash is caused by the SpriteFrames editor getting hidden, which causes frames to become null and also the SpinBox to lose focus, which in turn emits the value_changed signal. It's just unfortunate order of events and probably can't be fixed in a better way.

We could keep the fix limited to this single case. That risks another crash being discovered elsewhere, but prevents having too many unnecessary checks.

That's fine too. Though I'll keep the null check in _frame_duration_changed while I'm at it, since as mentioned in the bug report, this issue also affects the frame duration spinbox.

@Repiteo Repiteo merged commit c374ce2 into godotengine:master Apr 9, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Apr 9, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tabbing into a different scene while editing SpriteFrames FPS causes the editor to crash
4 participants