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

Change CRASH_COND to ERR_FAIL in Cowdata::set #36476

Merged
merged 1 commit into from
Feb 24, 2021

Conversation

qarmin
Copy link
Contributor

@qarmin qarmin commented Feb 23, 2020

Fixes #46395

Since #36311, some functions which used to ERR_FAIL macro inside PoolVector set function like

void Line2D::set_point_position(int i, Vector2 p_pos) {
	_points.set(i, p_pos);
	update();
}

now use Vector set function with CRASH_COND which cause a lot of crashes

Vector.h set function now

_FORCE_INLINE_ void set(int p_index, const T &p_elem) { _cowdata.set(p_index, p_elem); }

and inside cowdata

godot/core/cowdata.h

Lines 136 to 141 in 6fc50d7

_FORCE_INLINE_ void set(int p_index, const T &p_elem) {
CRASH_BAD_INDEX(p_index, size());
_copy_on_write();
_get_data()[p_index] = p_elem;
}

and PoolVector function

godot/core/pool_vector.h

Lines 490 to 497 in 6fc50d7

template <class T>
void PoolVector<T>::set(int p_index, const T &p_val) {
ERR_FAIL_INDEX(p_index, size());
Write w = write();
w[p_index] = p_val;
}

@akien-mga
Copy link
Member

Some comments from IRC:

11:59 <@Akien> reduz: WDYT about #36476 ? Should we do that or change CowData to fail instead of crash?
12:03 <reduz> the GET functions should crash
12:03 <reduz> the set functions I don't know, I don't care either way

So maybe we can make CowData set ERR_FAIL instead of crashing.

@qarmin qarmin changed the title Change CRASH_COND to ERR_FAIL in Vector Change CRASH_COND to ERR_FAIL in Cowdata::set Apr 5, 2020
@qarmin
Copy link
Contributor Author

qarmin commented Apr 5, 2020

I think that is good to change in Cowdata::set CRASH_COND to ERR_FAIL to prevent crashes, but for more detailed errors a check like in Line2D from this PR should be provided.

@qarmin qarmin force-pushed the vector_set_err branch 3 times, most recently from c707b41 to 674bf5e Compare July 23, 2020 08:33
@qarmin qarmin requested a review from a team as a code owner February 24, 2021 20:36
@akien-mga akien-mga merged commit 273fe7e into godotengine:master Feb 24, 2021
@akien-mga
Copy link
Member

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.

Executing Packed*Array.set crashes Godot
3 participants