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

[3.x] Initialize class variables with default values #44125

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,8 @@ void _Directory::_bind_methods() {
_Directory::_Directory() {

d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
_list_skip_hidden = false;
_list_skip_navigational = false;
}

_Directory::~_Directory() {
Expand Down
1 change: 1 addition & 0 deletions core/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ ClassDB::ClassInfo::ClassInfo() {
inherits_ptr = NULL;
disabled = false;
exposed = false;
class_ptr = NULL;
}

ClassDB::ClassInfo::~ClassInfo() {
Expand Down
1 change: 1 addition & 0 deletions core/crypto/hashing_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void HashingContext::_bind_methods() {
}

HashingContext::HashingContext() {
type = HASH_MD5;
ctx = NULL;
}

Expand Down
1 change: 1 addition & 0 deletions core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Engine::Engine() {
_in_physics = false;
_frame_ticks = 0;
_frame_step = 0;
_snap_2d_viewports = false;
editor_hint = false;
}

Expand Down
1 change: 1 addition & 0 deletions core/io/file_access_compressed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t
FileAccessCompressed::FileAccessCompressed() :
cmode(Compression::MODE_ZSTD),
writing(false),
write_pos(0),
write_ptr(0),
write_buffer_size(0),
write_max(0),
Expand Down
2 changes: 2 additions & 0 deletions core/io/file_access_encrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ FileAccessEncrypted::FileAccessEncrypted() {
eofed = false;
mode = MODE_MAX;
writing = false;
base = 0;
length = 0;
}

FileAccessEncrypted::~FileAccessEncrypted() {
Expand Down
2 changes: 2 additions & 0 deletions core/io/file_access_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,6 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) {
FileAccessMemory::FileAccessMemory() {

data = NULL;
length = 0;
pos = 0;
}
1 change: 1 addition & 0 deletions core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ HTTPClient::HTTPClient() {
handshaking = false;
// 64 KiB by default (favors fast download speeds at the cost of memory usage).
read_chunk_size = 65536;
ssl_verify_host = false;
}

HTTPClient::~HTTPClient() {
Expand Down
2 changes: 1 addition & 1 deletion core/io/pck_packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Error PCKPacker::flush(bool p_verbose) {
};

PCKPacker::PCKPacker() {

alignment = 0;
file = NULL;
};

Expand Down
2 changes: 2 additions & 0 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ ResourceInteractiveLoaderBinary::ResourceInteractiveLoaderBinary() :
f(NULL),
error(OK),
stage(0) {
ver_format = 0;
importmd_ofs = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why are some of these before the { and some after it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initializer list(before {) require to have all variables in same order as in class definition, so for me it was easier to write such code(in master initialization was moved from constructor)

}

ResourceInteractiveLoaderBinary::~ResourceInteractiveLoaderBinary() {
Expand Down
7 changes: 6 additions & 1 deletion core/math/a_star.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ class AStar : public Reference {
struct Point {

Point() :
id(0),
enabled(false),
neighbours(4u),
unlinked_neighbours(4u) {}
unlinked_neighbours(4u),
prev_point(NULL),
open_pass(0),
closed_pass(0) {}

int id;
Vector3 pos;
Expand Down
2 changes: 2 additions & 0 deletions core/math/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,8 @@ Expression::Expression() :
root(NULL),
nodes(NULL),
execution_error(false) {
str_ofs = 0;
expression_dirty = false;
}

Expression::~Expression() {
Expand Down
13 changes: 12 additions & 1 deletion core/math/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ class Expression : public Reference {

Type type;

ENode() { next = NULL; }
ENode() {
type = TYPE_INPUT;
next = NULL;
}
virtual ~ENode() {
if (next) {
memdelete(next);
Expand All @@ -243,6 +246,7 @@ class Expression : public Reference {

int index;
InputNode() {
index = 0;
type = TYPE_INPUT;
}
};
Expand All @@ -262,6 +266,8 @@ class Expression : public Reference {
ENode *nodes[2];

OperatorNode() {
nodes[0] = nullptr;
nodes[1] = nullptr;
type = TYPE_OPERATOR;
}
};
Expand All @@ -278,6 +284,8 @@ class Expression : public Reference {
ENode *index;

IndexNode() {
base = nullptr;
index = nullptr;
type = TYPE_INDEX;
}
};
Expand All @@ -287,6 +295,7 @@ class Expression : public Reference {
StringName name;

NamedIndexNode() {
base = nullptr;
type = TYPE_NAMED_INDEX;
}
};
Expand All @@ -306,6 +315,7 @@ class Expression : public Reference {
Vector<ENode *> arguments;

CallNode() {
base = nullptr;
type = TYPE_CALL;
}
};
Expand All @@ -328,6 +338,7 @@ class Expression : public Reference {
BuiltinFunc func;
Vector<ENode *> arguments;
BuiltinFuncNode() {
func = BuiltinFunc::BYTES_TO_VAR;
type = TYPE_BUILTIN_FUNC;
}
};
Expand Down
5 changes: 4 additions & 1 deletion core/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,10 @@ class Object {
int reference_count;
Connection conn;
List<Connection>::Element *cE;
Slot() { reference_count = 0; }
Slot() {
cE = nullptr;
reference_count = 0;
}
};

MethodInfo user;
Expand Down
2 changes: 1 addition & 1 deletion core/os/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ bool DirAccess::exists(String p_dir) {
}

DirAccess::DirAccess() {

next_is_dir = false;
_access_type = ACCESS_FILESYSTEM;
}

Expand Down
1 change: 1 addition & 0 deletions core/packed_data_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,5 @@ int PackedDataContainerRef::size() const {
};

PackedDataContainerRef::PackedDataContainerRef() {
offset = 0;
}
4 changes: 4 additions & 0 deletions core/script_debugger_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ void ScriptDebuggerLocal::send_error(const String &p_func, const String &p_file,

ScriptDebuggerLocal::ScriptDebuggerLocal() {

frame_time = 0;
idle_time = 0;
physics_time = 0;
physics_frame_time = 0;
profiling = false;
idle_accum = OS::get_singleton()->get_ticks_usec();
options["variable_prefix"] = "";
Expand Down
5 changes: 5 additions & 0 deletions drivers/alsa/audio_driver_alsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ AudioDriverALSA::AudioDriverALSA() :
pcm_handle(NULL),
device_name("Default"),
new_device("Default") {
mix_rate = 0;
channels = 0;
active = 0;
thread_exited = false;
exit_thread = false;
}

AudioDriverALSA::~AudioDriverALSA() {
Expand Down
14 changes: 14 additions & 0 deletions drivers/gles2/rasterizer_storage_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
vertex_mem(0) {
render.reset();
render_final.reset();
snap.reset();
}

} info;
Expand Down Expand Up @@ -229,6 +230,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
virtual void material_changed_notify() {}

Geometry() {
type = GEOMETRY_INVALID;
last_pass = 0;
index = 0;
}
Expand Down Expand Up @@ -296,6 +298,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
flags(0),
width(0),
height(0),
depth(0),
alloc_width(0),
alloc_height(0),
format(Image::FORMAT_L8),
Expand All @@ -305,6 +308,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
total_data_size(0),
ignore_mipmaps(false),
compressed(false),
srgb(false),
mipmaps(0),
resize_to_po2(false),
active(false),
Expand Down Expand Up @@ -532,6 +536,10 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
custom_code_id = 0;
version = 1;
last_pass = 0;
texture_count = 0;
index = 0;
uses_vertex_time = false;
uses_fragment_time = false;
}
};

Expand Down Expand Up @@ -588,6 +596,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
line_width = 1.0;
last_pass = 0;
render_priority = 0;
index = 0;
}
};

Expand Down Expand Up @@ -688,6 +697,8 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
primitive(VS::PRIMITIVE_POINTS),
active(false),
total_data_size(0) {
format = 0;
max_bone = 0;
}
};

Expand Down Expand Up @@ -720,6 +731,8 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
Mesh() :
blend_shape_count(0),
blend_shape_mode(VS::BLEND_SHAPE_MODE_NORMALIZED) {
active = false;
last_pass = 0;
}
};

Expand Down Expand Up @@ -859,6 +872,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {
Immediate() {
type = GEOMETRY_IMMEDIATE;
building = false;
mask = 0;
}
};

Expand Down
20 changes: 20 additions & 0 deletions drivers/gles3/rasterizer_storage_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
vertex_mem = 0;
render.reset();
render_final.reset();
snap.reset();
}

} info;
Expand Down Expand Up @@ -240,6 +241,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
virtual void material_changed_notify() {}

Geometry() {
type = GEOMETRY_INVALID;
last_pass = 0;
index = 0;
}
Expand Down Expand Up @@ -326,6 +328,11 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
detect_srgb_ud(NULL),
detect_normal(NULL),
detect_normal_ud(NULL) {
depth = 0;
alloc_width = 0;
alloc_height = 0;
alloc_depth = 0;
is_npot_repeat_mipmap = false;
}

_ALWAYS_INLINE_ Texture *get_ptr() {
Expand Down Expand Up @@ -544,6 +551,9 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
valid = false;
custom_code_id = 0;
version = 1;
texture_count = 0;
uses_fragment_time = false;
uses_vertex_time = false;
}
};

Expand Down Expand Up @@ -606,6 +616,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
last_pass(0),
can_cast_shadow_cache(false),
is_animated_cache(false) {
index = 0;
}
};

Expand Down Expand Up @@ -724,6 +735,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
active(false),
total_data_size(0) {
type = GEOMETRY_SURFACE;
max_bone = 0;
}

~Surface() {
Expand Down Expand Up @@ -1129,6 +1141,10 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
GIProbeCompression compression;

GIProbeData() {
width = 0;
height = 0;
depth = 0;
levels = 0;
}
};

Expand Down Expand Up @@ -1243,6 +1259,10 @@ class RasterizerStorageGLES3 : public RasterizerStorage {
fractional_delta(false),
frame_remainder(0),
clear(true) {
phase = 0;
prev_phase = 0;
particle_valid_histories[0] = false;
particle_valid_histories[1] = false;
particle_buffers[0] = 0;
particle_buffers[1] = 0;
glGenBuffers(2, particle_buffers);
Expand Down
3 changes: 3 additions & 0 deletions drivers/windows/dir_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ String DirAccessWindows::get_filesystem_type() const {

DirAccessWindows::DirAccessWindows() {

_cisdir = false;
_cishidden = false;

p = memnew(DirAccessWindowsPrivate);
p->h = INVALID_HANDLE_VALUE;
current_dir = ".";
Expand Down
1 change: 1 addition & 0 deletions drivers/windows/thread_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void ThreadWindows::make_default() {

ThreadWindows::ThreadWindows() :
handle(NULL) {
user = NULL;
}

ThreadWindows::~ThreadWindows() {
Expand Down
Loading