-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add explicit error messages to Multimesh functions #101109
Open
clayjohn
wants to merge
1
commit into
godotengine:master
Choose a base branch
from
clayjohn:multimesh-err-msg
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+26
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,12 @@ void MultiMesh::set_buffer(const Vector<float> &p_buffer) { | |
if (instance_count == 0) { | ||
return; | ||
} | ||
|
||
uint32_t stride = transform_format == TRANSFORM_2D ? 8 : 12; | ||
stride += use_colors ? 4 : 0; | ||
stride += use_custom_data ? 4 : 0; | ||
ERR_FAIL_COND_MSG(stride * instance_count != p_buffer.size(), "Cannot set a buffer on a Multimesh that is a different size from the Multimeshes existing buffer."); | ||
|
||
RS::get_singleton()->multimesh_set_buffer(multimesh, p_buffer); | ||
} | ||
|
||
|
@@ -249,39 +255,56 @@ void MultiMesh::set_physics_interpolation_quality(PhysicsInterpolationQuality p_ | |
} | ||
|
||
void MultiMesh::set_instance_transform(int p_instance, const Transform3D &p_transform) { | ||
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should say non-negative rather than positive (to include zero). |
||
ERR_FAIL_COND_MSG(transform_format == TRANSFORM_2D, "Can't set Transform3D on a Multimesh configured to use Transform2D. Ensure that you have set the `transform_format` to `TRANSFORM_3D`."); | ||
RenderingServer::get_singleton()->multimesh_instance_set_transform(multimesh, p_instance, p_transform); | ||
} | ||
|
||
void MultiMesh::set_instance_transform_2d(int p_instance, const Transform2D &p_transform) { | ||
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
ERR_FAIL_COND_MSG(transform_format == TRANSFORM_3D, "Can't set Transform2D on a Multimesh configured to use Transform3D. Ensure that you have set the `transform_format` to `TRANSFORM_2D`."); | ||
RenderingServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform); | ||
emit_changed(); | ||
} | ||
|
||
Transform3D MultiMesh::get_instance_transform(int p_instance) const { | ||
ERR_FAIL_INDEX_V_MSG(p_instance, instance_count, Transform3D(), "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
ERR_FAIL_COND_V_MSG(transform_format == TRANSFORM_2D, Transform3D(), "Can't get Transform3D on a Multimesh configured to use Transform2D. Ensure that you have set the `transform_format` to `TRANSFORM_3D`."); | ||
return RenderingServer::get_singleton()->multimesh_instance_get_transform(multimesh, p_instance); | ||
} | ||
|
||
Transform2D MultiMesh::get_instance_transform_2d(int p_instance) const { | ||
ERR_FAIL_INDEX_V_MSG(p_instance, instance_count, Transform2D(), "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
ERR_FAIL_COND_V_MSG(transform_format == TRANSFORM_3D, Transform2D(), "Can't get Transform2D on a Multimesh configured to use Transform3D. Ensure that you have set the `transform_format` to `TRANSFORM_2D`."); | ||
return RenderingServer::get_singleton()->multimesh_instance_get_transform_2d(multimesh, p_instance); | ||
} | ||
|
||
void MultiMesh::set_instance_color(int p_instance, const Color &p_color) { | ||
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
ERR_FAIL_COND_MSG(!use_colors, "Can't set instance color on a Multimesh that isn't using colors. Ensure that you have `use_colors` property of this Multimesh set to `true`."); | ||
RenderingServer::get_singleton()->multimesh_instance_set_color(multimesh, p_instance, p_color); | ||
} | ||
|
||
Color MultiMesh::get_instance_color(int p_instance) const { | ||
ERR_FAIL_INDEX_V_MSG(p_instance, instance_count, Color(), "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
ERR_FAIL_COND_V_MSG(!use_colors, Color(), "Can't get instance color on a Multimesh that isn't using colors. Ensure that you have `use_colors` property of this Multimesh set to `true`."); | ||
return RenderingServer::get_singleton()->multimesh_instance_get_color(multimesh, p_instance); | ||
} | ||
|
||
void MultiMesh::set_instance_custom_data(int p_instance, const Color &p_custom_data) { | ||
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
ERR_FAIL_COND_MSG(!use_custom_data, "Can't get instance custom data on a Multimesh that isn't using custom data. Ensure that you have `use_custom_data` property of this Multimesh set to `true`."); | ||
RenderingServer::get_singleton()->multimesh_instance_set_custom_data(multimesh, p_instance, p_custom_data); | ||
} | ||
|
||
Color MultiMesh::get_instance_custom_data(int p_instance) const { | ||
ERR_FAIL_INDEX_V_MSG(p_instance, instance_count, Color(), "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
ERR_FAIL_COND_V_MSG(!use_custom_data, Color(), "Can't get instance custom data on a Multimesh that isn't using custom data. Ensure that you have `use_custom_data` property of this Multimesh set to `true`."); | ||
return RenderingServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance); | ||
} | ||
|
||
void MultiMesh::reset_instance_physics_interpolation(int p_instance) { | ||
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be a positive number that is less than `instance_count`."); | ||
RenderingServer::get_singleton()->multimesh_instance_reset_physics_interpolation(multimesh, p_instance); | ||
} | ||
|
||
|
@@ -308,7 +331,7 @@ RID MultiMesh::get_rid() const { | |
} | ||
|
||
void MultiMesh::set_use_colors(bool p_enable) { | ||
ERR_FAIL_COND(instance_count > 0); | ||
ERR_FAIL_COND_MSG(instance_count > 0, "Instance count must be 0 to toggle whether colors are used."); | ||
use_colors = p_enable; | ||
} | ||
|
||
|
@@ -317,7 +340,7 @@ bool MultiMesh::is_using_colors() const { | |
} | ||
|
||
void MultiMesh::set_use_custom_data(bool p_enable) { | ||
ERR_FAIL_COND(instance_count > 0); | ||
ERR_FAIL_COND_MSG(instance_count > 0, "Instance count must be 0 to toggle whether custom data is used."); | ||
use_custom_data = p_enable; | ||
} | ||
|
||
|
@@ -326,7 +349,7 @@ bool MultiMesh::is_using_custom_data() const { | |
} | ||
|
||
void MultiMesh::set_transform_format(TransformFormat p_transform_format) { | ||
ERR_FAIL_COND(instance_count > 0); | ||
ERR_FAIL_COND_MSG(instance_count > 0, "Instance count must be 0 to change the transform format."); | ||
transform_format = p_transform_format; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.