Skip to content

Fix crash when using a modulo operator between a float and an integer #101536

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
Jul 1, 2025

Conversation

xsellier
Copy link
Contributor

@xsellier xsellier commented Jan 14, 2025

Thanks to this change this scripts:

extends SceneTree

func _init():
  var result = randi() % floor(10.0)

Returns this error:

SCRIPT ERROR: Invalid operands 'int' and 'float' in operator '%'.
          at: _init (res://crash.gd:4)

Otherwise it used to crash

Bugsquad edit:

@xsellier xsellier requested a review from a team as a code owner January 14, 2025 11:54
@akien-mga
Copy link
Member

Could you amend the commit title and PR title to be an explicit description of what bug is being fixed, and not what issue number or how it's fixed? See https://github.com/godotengine/godot/blob/master/CONTRIBUTING.md#format-your-commit-messages-with-readability-in-mind for our guidelines on commit messages.

@xsellier xsellier force-pushed the gdscript_crash_modulo branch from 416c5b1 to b850964 Compare January 14, 2025 14:07
@xsellier xsellier changed the title Fix #80486 Fix crash when using a modulo operator between a float and an integer Jan 14, 2025
@xsellier
Copy link
Contributor Author

Could you amend the commit title and PR title to be an explicit description of what bug is being fixed, and not what issue number or how it's fixed? See https://github.com/godotengine/godot/blob/master/CONTRIBUTING.md#format-your-commit-messages-with-readability-in-mind for our guidelines on commit messages.

Done, sorry for that commit message, I should have known better

@Repiteo Repiteo modified the milestones: 4.4, 4.5 Feb 24, 2025
@xsellier
Copy link
Contributor Author

Any news on that matter ?

@Chaosus Chaosus requested a review from dalexeev April 17, 2025 07:46
@vnen
Copy link
Member

vnen commented Jul 1, 2025

I'm a bit torn about this. On one hand it does solve the crash in a simple way, but it also postpones the error until runtime (and the error will happen). We can catch the error on editor and show it to the user, which is why I prefer my own take in #83559 (which is more intrusive, sure, but it's also better usability).

We could merge this to solve the crash. But then I wonder if we ever gonna improve the editor for this case.

I guess it's better to stop the crash for now.

@Repiteo Repiteo merged commit 2cf48a9 into godotengine:master Jul 1, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jul 1, 2025

Thanks!

@xsellier xsellier deleted the gdscript_crash_modulo branch July 2, 2025 06:10
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.

Calling randi() % floor(2.0) causes engine to crash silently
4 participants