Skip to content

Commit e1af7b6

Browse files
clayjohnakien-mga
authored andcommitted
Add explicit error messages to Multimesh error functions to make errors easier to understand.
Previously the RenderingServer errors filtered up to end users, but they are unclear and not helpful
1 parent a63a8b4 commit e1af7b6

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

scene/resources/multimesh.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ void MultiMesh::set_buffer(const Vector<float> &p_buffer) {
198198
if (instance_count == 0) {
199199
return;
200200
}
201+
202+
uint32_t stride = transform_format == TRANSFORM_2D ? 8 : 12;
203+
stride += use_colors ? 4 : 0;
204+
stride += use_custom_data ? 4 : 0;
205+
ERR_FAIL_COND_MSG(stride * instance_count != p_buffer.size(), "Cannot set a buffer on a Multimesh that is a different size from the Multimesh's existing buffer.");
206+
201207
RS::get_singleton()->multimesh_set_buffer(multimesh, p_buffer);
202208
}
203209

@@ -249,39 +255,56 @@ void MultiMesh::set_physics_interpolation_quality(PhysicsInterpolationQuality p_
249255
}
250256

251257
void MultiMesh::set_instance_transform(int p_instance, const Transform3D &p_transform) {
258+
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
259+
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`.");
252260
RenderingServer::get_singleton()->multimesh_instance_set_transform(multimesh, p_instance, p_transform);
253261
}
254262

255263
void MultiMesh::set_instance_transform_2d(int p_instance, const Transform2D &p_transform) {
264+
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
265+
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`.");
256266
RenderingServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform);
257267
emit_changed();
258268
}
259269

260270
Transform3D MultiMesh::get_instance_transform(int p_instance) const {
271+
ERR_FAIL_INDEX_V_MSG(p_instance, instance_count, Transform3D(), "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
272+
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`.");
261273
return RenderingServer::get_singleton()->multimesh_instance_get_transform(multimesh, p_instance);
262274
}
263275

264276
Transform2D MultiMesh::get_instance_transform_2d(int p_instance) const {
277+
ERR_FAIL_INDEX_V_MSG(p_instance, instance_count, Transform2D(), "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
278+
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`.");
265279
return RenderingServer::get_singleton()->multimesh_instance_get_transform_2d(multimesh, p_instance);
266280
}
267281

268282
void MultiMesh::set_instance_color(int p_instance, const Color &p_color) {
283+
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
284+
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`.");
269285
RenderingServer::get_singleton()->multimesh_instance_set_color(multimesh, p_instance, p_color);
270286
}
271287

272288
Color MultiMesh::get_instance_color(int p_instance) const {
289+
ERR_FAIL_INDEX_V_MSG(p_instance, instance_count, Color(), "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
290+
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`.");
273291
return RenderingServer::get_singleton()->multimesh_instance_get_color(multimesh, p_instance);
274292
}
275293

276294
void MultiMesh::set_instance_custom_data(int p_instance, const Color &p_custom_data) {
295+
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
296+
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`.");
277297
RenderingServer::get_singleton()->multimesh_instance_set_custom_data(multimesh, p_instance, p_custom_data);
278298
}
279299

280300
Color MultiMesh::get_instance_custom_data(int p_instance) const {
301+
ERR_FAIL_INDEX_V_MSG(p_instance, instance_count, Color(), "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
302+
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`.");
281303
return RenderingServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance);
282304
}
283305

284306
void MultiMesh::reset_instance_physics_interpolation(int p_instance) {
307+
ERR_FAIL_INDEX_MSG(p_instance, instance_count, "Instance index out of bounds. Instance index must be less than `instance_count` and greater than or equal to zero.");
285308
RenderingServer::get_singleton()->multimesh_instance_reset_physics_interpolation(multimesh, p_instance);
286309
}
287310

@@ -308,7 +331,7 @@ RID MultiMesh::get_rid() const {
308331
}
309332

310333
void MultiMesh::set_use_colors(bool p_enable) {
311-
ERR_FAIL_COND(instance_count > 0);
334+
ERR_FAIL_COND_MSG(instance_count > 0, "Instance count must be 0 to toggle whether colors are used.");
312335
use_colors = p_enable;
313336
}
314337

@@ -317,7 +340,7 @@ bool MultiMesh::is_using_colors() const {
317340
}
318341

319342
void MultiMesh::set_use_custom_data(bool p_enable) {
320-
ERR_FAIL_COND(instance_count > 0);
343+
ERR_FAIL_COND_MSG(instance_count > 0, "Instance count must be 0 to toggle whether custom data is used.");
321344
use_custom_data = p_enable;
322345
}
323346

@@ -326,7 +349,7 @@ bool MultiMesh::is_using_custom_data() const {
326349
}
327350

328351
void MultiMesh::set_transform_format(TransformFormat p_transform_format) {
329-
ERR_FAIL_COND(instance_count > 0);
352+
ERR_FAIL_COND_MSG(instance_count > 0, "Instance count must be 0 to change the transform format.");
330353
transform_format = p_transform_format;
331354
}
332355

0 commit comments

Comments
 (0)