mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
Fixed a memleak.
This commit is contained in:
parent
34e109a54b
commit
63c7c0536c
@ -56,7 +56,7 @@ Ref<VoxelmanLibrary> VoxelSurface::get_library() const {
|
||||
}
|
||||
|
||||
void VoxelSurface::set_library(Ref<VoxelmanLibrary> library) {
|
||||
_library = library;
|
||||
_library = (*library);
|
||||
}
|
||||
|
||||
Vector2 VoxelSurface::transform_uv(const int side, const Vector2 uv) const {
|
||||
@ -74,6 +74,8 @@ VoxelSurface::VoxelSurface() {
|
||||
}
|
||||
|
||||
_is_transparent = false;
|
||||
|
||||
_library = NULL;
|
||||
}
|
||||
|
||||
VoxelSurface::VoxelSurface(int id) {
|
||||
@ -84,10 +86,12 @@ VoxelSurface::VoxelSurface(int id) {
|
||||
}
|
||||
|
||||
_is_transparent = false;
|
||||
|
||||
_library = NULL;
|
||||
}
|
||||
|
||||
VoxelSurface::~VoxelSurface() {
|
||||
_library.unref();
|
||||
//_library = NULL;
|
||||
}
|
||||
|
||||
void VoxelSurface::_bind_methods() {
|
||||
|
@ -66,7 +66,7 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Ref<VoxelmanLibrary> _library;
|
||||
VoxelmanLibrary *_library;
|
||||
|
||||
int _id;
|
||||
String _name;
|
||||
|
@ -12,13 +12,21 @@ VoxelmanLibrary::VoxelmanLibrary() {
|
||||
|
||||
for (int i = 0; i < MAX_VOXEL_TYPES; ++i) {
|
||||
if (_voxel_types[i] != NULL) {
|
||||
print_error("set_this");
|
||||
_voxel_types[i]->set_library(Ref<VoxelmanLibrary>(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VoxelmanLibrary::~VoxelmanLibrary() {
|
||||
for (int i = 0; i < MAX_VOXEL_TYPES; ++i) {
|
||||
if (_voxel_types[i].is_valid()) {
|
||||
_voxel_types[i]->set_library(Ref<VoxelmanLibrary>(NULL));
|
||||
_voxel_types[i].unref();
|
||||
}
|
||||
}
|
||||
|
||||
_material.unref();
|
||||
_prop_material.unref();
|
||||
}
|
||||
|
||||
Ref<VoxelSurface> VoxelmanLibrary::get_voxel_surface(int index) const {
|
||||
@ -29,10 +37,12 @@ Ref<VoxelSurface> VoxelmanLibrary::get_voxel_surface(int index) const {
|
||||
|
||||
void VoxelmanLibrary::set_voxel_surface(int index, Ref<VoxelSurface> value) {
|
||||
ERR_FAIL_COND(index < 0 || index > _voxel_types_count);
|
||||
ERR_FAIL_COND(value == NULL);
|
||||
|
||||
if (value != NULL) {
|
||||
if (_voxel_types[index].is_valid()) {
|
||||
_voxel_types[index]->set_library(Ref<VoxelmanLibrary>(NULL));
|
||||
}
|
||||
|
||||
if (value.is_valid()) {
|
||||
value->set_library(Ref<VoxelmanLibrary>(this));
|
||||
|
||||
_voxel_types[index] = Ref<VoxelSurface>(value);
|
||||
|
Loading…
Reference in New Issue
Block a user