Skip to content
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

Allow up to INT32_MAX max size in Array/Dictionary editor #77225

Merged
merged 1 commit into from
May 22, 2023

Conversation

JBrowne017
Copy link
Contributor

Quick update to editor_properties_array_dict max size. An array in the EditorInspector won't display a number higher than 1,000,000. The Range::Shared max value is stored in a double, as such the new max value has been updated to be DBL_MAX instead of an arbitrary magic number.

Resolves #77190

@JBrowne017 JBrowne017 marked this pull request as ready for review May 19, 2023 06:08
@AThousandShips
Copy link
Member

AThousandShips commented May 19, 2023

DBL_MAX is far larger than the maximum possible size for an Array though, it can only reach the maximum of int, and even if it could become larger you lose precision after 2^53, and can no longer represent whole integers precisely, not to mention how int is 32 bits (even if it wouldn't be on some rare platforms Array is limited to 32 bits)

Also accidentally setting this size too high will cause errors as you run out of memory, not very user friendly, 2^53 entry arrays is some 144 petabytes, this would make it possible to attempt to make arrays taking some 2.8*10^309 bytes (twice as large if you use doubles)

But in any case DBL_MAX is not an appropriate value here, INT_MAX or 0x7fffffff would be the biggest it should be

@Chaosus Chaosus added this to the 4.1 milestone May 19, 2023
@@ -311,7 +311,7 @@ void EditorPropertyArray::update_property() {

size_slider = memnew(EditorSpinSlider);
size_slider->set_step(1);
size_slider->set_max(1000000);
size_slider->set_max(DBL_MAX);
Copy link
Member

@AThousandShips AThousandShips May 19, 2023

Choose a reason for hiding this comment

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

See my comment on this value, cannot be larger than INT_MAX or 0x7fffffff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea I was doing more diving into the codebase and was looking at where it was actually used and it would be better to use a integer value instead. Would you still recommend INT_MAX over something like UINT32_MAX? I don't know a case where you would need a negative array size and there are a few spots where I see the size being cast to a unsigned 32 bit integer anyways.

Copy link
Member

@AThousandShips AThousandShips May 19, 2023

Choose a reason for hiding this comment

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

It's a signed integer so not UINT32_MAX, the resize function takes int so don't think it's safe, the use of int for size across the codebase is a bit odd but let's stick to using it safely

I'm not sure if there's any use of INT32_MAX in the codebase but it's an optional constant so using INT_MAX or the actual value might be more portable

Edit: It has been used in various locations so it should be safe to just use INT32_MAX

@AThousandShips
Copy link
Member

AThousandShips commented May 19, 2023

You have duplicate and redundant commits, you will need to squash these, see here

And update the PR name and description to reflect the changes

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.

LGTM, some editor maintainer will have to give their opinion on if this is a good range but it makes sense to me and makes any exported array usable in the editor

@JBrowne017
Copy link
Contributor Author

Yea I'm currently doing that. It's just been a minute since I've done a large rebase and squash in general. Thanks for the heads up though.

Quick update to editor/editor_properties_array_dict max size.
Currently, an array in the EditorInspector won't display a number higher than 1,000,000.
In place of the current magic number this sets the max to be the INT32_MAX.
This eludes the magic number in place and is sufficiently large.

Resolves godotengine#77190
@AThousandShips
Copy link
Member

Remember to update the PR description and title

@akien-mga akien-mga changed the title Update editor_properties_array_dict to use DBL_MAX Allow up to INT32_MAX max size in Array/Dictionary editor May 22, 2023
@akien-mga akien-mga merged commit 5d16efa into godotengine:master May 22, 2023
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.0.4.

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.

When an array contains more than 1 000 000 elements the size EditorSpinSlider stays to 1 000 000
5 participants