Fix some crashes and using null pointers

This commit is contained in:
Rafał Mikrut 2019-10-28 08:07:29 +01:00
parent 4ecc30cc5e
commit e53e1c566a
15 changed files with 37 additions and 19 deletions

View File

@ -50,6 +50,7 @@ Error HashingContext::start(HashType p_type) {
Error HashingContext::update(PoolByteArray p_chunk) { Error HashingContext::update(PoolByteArray p_chunk) {
ERR_FAIL_COND_V(ctx == NULL, ERR_UNCONFIGURED); ERR_FAIL_COND_V(ctx == NULL, ERR_UNCONFIGURED);
size_t len = p_chunk.size(); size_t len = p_chunk.size();
ERR_FAIL_COND_V(len == 0, FAILED);
PoolByteArray::Read r = p_chunk.read(); PoolByteArray::Read r = p_chunk.read();
switch (type) { switch (type) {
case HASH_MD5: case HASH_MD5:

View File

@ -885,8 +885,8 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */; bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */;
ERR_FAIL_COND_MSG(p_width <= 0, "Image width cannot be greater than 0."); ERR_FAIL_COND_MSG(p_width <= 0, "Image width must be greater than 0.");
ERR_FAIL_COND_MSG(p_height <= 0, "Image height cannot be greater than 0."); ERR_FAIL_COND_MSG(p_height <= 0, "Image height must be greater than 0.");
ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + "."); ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + ".");
ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + "."); ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + ".");
@ -1322,6 +1322,8 @@ void Image::expand_x2_hq2x() {
PoolVector<uint8_t>::Read r = data.read(); PoolVector<uint8_t>::Read r = data.read();
PoolVector<uint8_t>::Write w = dest.write(); PoolVector<uint8_t>::Write w = dest.write();
ERR_FAIL_COND(!r.ptr());
hq2x_resize((const uint32_t *)r.ptr(), width, height, (uint32_t *)w.ptr()); hq2x_resize((const uint32_t *)r.ptr(), width, height, (uint32_t *)w.ptr());
} }
@ -2895,6 +2897,8 @@ void Image::bumpmap_to_normalmap(float bump_scale) {
PoolVector<uint8_t>::Read rp = data.read(); PoolVector<uint8_t>::Read rp = data.read();
PoolVector<uint8_t>::Write wp = result_image.write(); PoolVector<uint8_t>::Write wp = result_image.write();
ERR_FAIL_COND(!rp.ptr());
unsigned char *write_ptr = wp.ptr(); unsigned char *write_ptr = wp.ptr();
float *read_ptr = (float *)rp.ptr(); float *read_ptr = (float *)rp.ptr();

View File

@ -137,6 +137,7 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
int PackedDataContainer::_size(uint32_t p_ofs) const { int PackedDataContainer::_size(uint32_t p_ofs) const {
PoolVector<uint8_t>::Read rd = data.read(); PoolVector<uint8_t>::Read rd = data.read();
ERR_FAIL_COND_V(!rd.ptr(), 0);
const uint8_t *r = &rd[p_ofs]; const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r); uint32_t type = decode_uint32(r);

View File

@ -986,6 +986,7 @@ Array TranslationServer::get_loaded_locales() const {
for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) { for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) {
const Ref<Translation> &t = E->get(); const Ref<Translation> &t = E->get();
ERR_FAIL_COND_V(t.is_null(), Array());
String l = t->get_locale(); String l = t->get_locale();
locales.push_back(l); locales.push_back(l);
@ -1057,6 +1058,7 @@ StringName TranslationServer::translate(const StringName &p_message) const {
for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) { for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) {
const Ref<Translation> &t = E->get(); const Ref<Translation> &t = E->get();
ERR_FAIL_COND_V(t.is_null(), StringName(""));
String l = t->get_locale(); String l = t->get_locale();
if (lptr[0] != l[0] || lptr[1] != l[1]) if (lptr[0] != l[0] || lptr[1] != l[1])
continue; // Language code does not match. continue; // Language code does not match.
@ -1085,6 +1087,7 @@ StringName TranslationServer::translate(const StringName &p_message) const {
for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) { for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) {
const Ref<Translation> &t = E->get(); const Ref<Translation> &t = E->get();
ERR_FAIL_COND_V(t.is_null(), StringName(""));
String l = t->get_locale(); String l = t->get_locale();
if (fptr[0] != l[0] || fptr[1] != l[1]) if (fptr[0] != l[0] || fptr[1] != l[1])
continue; // Language code does not match. continue; // Language code does not match.

View File

@ -665,6 +665,7 @@ void RasterizerStorageGLES2::texture_set_data(RID p_texture, const Ref<Image> &p
texture->data_size = img->get_data().size(); texture->data_size = img->get_data().size();
PoolVector<uint8_t>::Read read = img->get_data().read(); PoolVector<uint8_t>::Read read = img->get_data().read();
ERR_FAIL_COND(!read.ptr());
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id); glBindTexture(texture->target, texture->tex_id);
@ -3236,12 +3237,14 @@ Color RasterizerStorageGLES2::multimesh_instance_get_custom_data(RID p_multimesh
void RasterizerStorageGLES2::multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array) { void RasterizerStorageGLES2::multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array) {
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
ERR_FAIL_COND(!multimesh); ERR_FAIL_COND(!multimesh);
ERR_FAIL_COND(!multimesh->data.ptr());
int dsize = multimesh->data.size(); int dsize = multimesh->data.size();
ERR_FAIL_COND(dsize != p_array.size()); ERR_FAIL_COND(dsize != p_array.size());
PoolVector<float>::Read r = p_array.read(); PoolVector<float>::Read r = p_array.read();
ERR_FAIL_COND(!r.ptr());
copymem(multimesh->data.ptrw(), r.ptr(), dsize * sizeof(float)); copymem(multimesh->data.ptrw(), r.ptr(), dsize * sizeof(float));
multimesh->dirty_data = true; multimesh->dirty_data = true;

View File

@ -795,6 +795,7 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref<Image> &p
texture->data_size = img->get_data().size(); texture->data_size = img->get_data().size();
PoolVector<uint8_t>::Read read = img->get_data().read(); PoolVector<uint8_t>::Read read = img->get_data().read();
ERR_FAIL_COND(!read.ptr());
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(texture->target, texture->tex_id); glBindTexture(texture->target, texture->tex_id);
@ -4718,6 +4719,7 @@ void RasterizerStorageGLES3::multimesh_set_as_bulk_array(RID p_multimesh, const
MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh); MultiMesh *multimesh = multimesh_owner.getornull(p_multimesh);
ERR_FAIL_COND(!multimesh); ERR_FAIL_COND(!multimesh);
ERR_FAIL_COND(!multimesh->data.ptr());
int dsize = multimesh->data.size(); int dsize = multimesh->data.size();
@ -4854,15 +4856,16 @@ RID RasterizerStorageGLES3::immediate_create() {
return immediate_owner.make_rid(im); return immediate_owner.make_rid(im);
} }
void RasterizerStorageGLES3::immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture) { void RasterizerStorageGLES3::immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture) {
ERR_FAIL_INDEX(p_primitive, (int)VS::PRIMITIVE_MAX);
Immediate *im = immediate_owner.get(p_immediate); Immediate *im = immediate_owner.get(p_immediate);
ERR_FAIL_COND(!im); ERR_FAIL_COND(!im);
ERR_FAIL_COND(im->building); ERR_FAIL_COND(im->building);
Immediate::Chunk ic; Immediate::Chunk ic;
ic.texture = p_texture; ic.texture = p_texture;
ic.primitive = p_rimitive; ic.primitive = p_primitive;
im->chunks.push_back(ic); im->chunks.push_back(ic);
im->mask = 0; im->mask = 0;
im->building = true; im->building = true;

View File

@ -869,7 +869,7 @@ public:
mutable RID_Owner<Immediate> immediate_owner; mutable RID_Owner<Immediate> immediate_owner;
virtual RID immediate_create(); virtual RID immediate_create();
virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture = RID()); virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture = RID());
virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex); virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex);
virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal); virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal);
virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent); virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent);

View File

@ -62,7 +62,7 @@ public:
virtual void setMargin(btScalar margin); virtual void setMargin(btScalar margin);
void setSlipsOnSlope(bool p_slipOnSlope); void setSlipsOnSlope(bool p_slipsOnSlope);
bool getSlipsOnSlope() const { return slipsOnSlope; } bool getSlipsOnSlope() const { return slipsOnSlope; }
const btTransform &getSupportPoint() const { return m_cacheSupportPoint; } const btTransform &getSupportPoint() const { return m_cacheSupportPoint; }

View File

@ -126,16 +126,16 @@ void BulletPhysicsDirectBodyState::add_torque(const Vector3 &p_torque) {
body->apply_torque(p_torque); body->apply_torque(p_torque);
} }
void BulletPhysicsDirectBodyState::apply_central_impulse(const Vector3 &p_j) { void BulletPhysicsDirectBodyState::apply_central_impulse(const Vector3 &p_impulse) {
body->apply_central_impulse(p_j); body->apply_central_impulse(p_impulse);
} }
void BulletPhysicsDirectBodyState::apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) { void BulletPhysicsDirectBodyState::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) {
body->apply_impulse(p_pos, p_j); body->apply_impulse(p_pos, p_impulse);
} }
void BulletPhysicsDirectBodyState::apply_torque_impulse(const Vector3 &p_j) { void BulletPhysicsDirectBodyState::apply_torque_impulse(const Vector3 &p_impulse) {
body->apply_torque_impulse(p_j); body->apply_torque_impulse(p_impulse);
} }
void BulletPhysicsDirectBodyState::set_sleep_state(bool p_enable) { void BulletPhysicsDirectBodyState::set_sleep_state(bool p_enable) {
@ -920,7 +920,7 @@ void RigidBodyBullet::reload_space_override_modificator() {
currentArea = areasWhereIam[i]; currentArea = areasWhereIam[i];
if (PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED == currentArea->get_spOv_mode()) { if (!currentArea || PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED == currentArea->get_spOv_mode()) {
continue; continue;
} }

View File

@ -114,8 +114,8 @@ public:
virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos); virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos);
virtual void add_torque(const Vector3 &p_torque); virtual void add_torque(const Vector3 &p_torque);
virtual void apply_central_impulse(const Vector3 &p_impulse); virtual void apply_central_impulse(const Vector3 &p_impulse);
virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j); virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
virtual void apply_torque_impulse(const Vector3 &p_j); virtual void apply_torque_impulse(const Vector3 &p_impulse);
virtual void set_sleep_state(bool p_enable); virtual void set_sleep_state(bool p_enable);
virtual bool is_sleeping() const; virtual bool is_sleeping() const;

View File

@ -168,6 +168,7 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
} }
PoolVector<uint8_t>::Read r = img->get_data().read(); PoolVector<uint8_t>::Read r = img->get_data().read();
ERR_FAIL_COND(!r.ptr());
unsigned int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps()); unsigned int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps());
int mmc = 1 + (p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0); int mmc = 1 + (p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0);

View File

@ -132,7 +132,7 @@ void GDAPI godot_array_destroy(godot_array *p_self);
godot_array GDAPI godot_array_duplicate(const godot_array *p_self, const godot_bool p_deep); godot_array GDAPI godot_array_duplicate(const godot_array *p_self, const godot_bool p_deep);
godot_array GDAPI godot_array_slice(const godot_array *p_self, const godot_int p_begin, const godot_int p_end, const godot_int p_delta, const godot_bool p_deep); godot_array GDAPI godot_array_slice(const godot_array *p_self, const godot_int p_begin, const godot_int p_end, const godot_int p_step, const godot_bool p_deep);
godot_variant GDAPI godot_array_max(const godot_array *p_self); godot_variant GDAPI godot_array_max(const godot_array *p_self);

View File

@ -158,7 +158,7 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty
String additional_code = "extern void register_dynamic_symbol(char *name, void *address);\n" String additional_code = "extern void register_dynamic_symbol(char *name, void *address);\n"
"extern void add_ios_init_callback(void (*cb)());\n"; "extern void add_ios_init_callback(void (*cb)());\n";
String linker_flags = ""; String linker_flags = "";
for (unsigned int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) { for (unsigned long i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) {
String full_name = lib->get_symbol_prefix() + expected_symbols[i].name; String full_name = lib->get_symbol_prefix() + expected_symbols[i].name;
String code = declare_pattern.replace("$name", full_name); String code = declare_pattern.replace("$name", full_name);
code = code.replace("$weak", expected_symbols[i].is_required ? "" : " __attribute__((weak))"); code = code.replace("$weak", expected_symbols[i].is_required ? "" : " __attribute__((weak))");
@ -174,7 +174,7 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty
additional_code += String("void $prefixinit() {\n").replace("$prefix", lib->get_symbol_prefix()); additional_code += String("void $prefixinit() {\n").replace("$prefix", lib->get_symbol_prefix());
String register_pattern = " if (&$name) register_dynamic_symbol((char *)\"$name\", (void *)$name);\n"; String register_pattern = " if (&$name) register_dynamic_symbol((char *)\"$name\", (void *)$name);\n";
for (unsigned int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) { for (unsigned long i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) {
String full_name = lib->get_symbol_prefix() + expected_symbols[i].name; String full_name = lib->get_symbol_prefix() + expected_symbols[i].name;
additional_code += register_pattern.replace("$name", full_name); additional_code += register_pattern.replace("$name", full_name);
} }

View File

@ -124,7 +124,7 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value); void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const; bool get_collision_mask_bit(int p_bit) const;
void set_source_geometry_mode(int p_source_mode); void set_source_geometry_mode(int p_geometry_mode);
int get_source_geometry_mode() const; int get_source_geometry_mode() const;
void set_source_group_name(StringName p_group_name); void set_source_group_name(StringName p_group_name);

View File

@ -1754,6 +1754,7 @@ SpatialMaterial::TextureChannel SpatialMaterial::get_roughness_texture_channel()
void SpatialMaterial::set_ao_texture_channel(TextureChannel p_channel) { void SpatialMaterial::set_ao_texture_channel(TextureChannel p_channel) {
ERR_FAIL_INDEX(p_channel, 5);
ao_texture_channel = p_channel; ao_texture_channel = p_channel;
VS::get_singleton()->material_set_param(_get_material(), shader_names->ao_texture_channel, _get_texture_mask(p_channel)); VS::get_singleton()->material_set_param(_get_material(), shader_names->ao_texture_channel, _get_texture_mask(p_channel));
} }
@ -1764,6 +1765,7 @@ SpatialMaterial::TextureChannel SpatialMaterial::get_ao_texture_channel() const
void SpatialMaterial::set_refraction_texture_channel(TextureChannel p_channel) { void SpatialMaterial::set_refraction_texture_channel(TextureChannel p_channel) {
ERR_FAIL_INDEX(p_channel, 5);
refraction_texture_channel = p_channel; refraction_texture_channel = p_channel;
VS::get_singleton()->material_set_param(_get_material(), shader_names->refraction_texture_channel, _get_texture_mask(p_channel)); VS::get_singleton()->material_set_param(_get_material(), shader_names->refraction_texture_channel, _get_texture_mask(p_channel));
} }