Don't declare a WeakRef as non-reference, causes issues with ObjectDB

This commit is contained in:
Marc Gilleron 2018-09-29 17:07:15 +01:00
parent 44bdc63c6f
commit b117a2a336
2 changed files with 17 additions and 11 deletions

View File

@ -5,14 +5,15 @@
#define STRLEN(x) (sizeof(x) / sizeof(x[0])) #define STRLEN(x) (sizeof(x) / sizeof(x[0]))
Voxel::Voxel() Voxel::Voxel():
: Resource(), _library(0),
_id(-1), _id(-1),
_material_id(0), _material_id(0),
_is_transparent(false), _is_transparent(false),
_color(1.f, 1.f, 1.f), _color(1.f, 1.f, 1.f),
_geometry_type(GEOMETRY_NONE), _geometry_type(GEOMETRY_NONE),
_cube_geometry_padding_y(0) {} _cube_geometry_padding_y(0)
{}
static Voxel::Side name_to_side(const String &s) { static Voxel::Side name_to_side(const String &s) {
if (s == "left") if (s == "left")
@ -158,13 +159,18 @@ Voxel::GeometryType Voxel::get_geometry_type() const {
} }
void Voxel::set_library(Ref<VoxelLibrary> lib) { void Voxel::set_library(Ref<VoxelLibrary> lib) {
_library.set_ref(lib); if(lib.is_null())
_library = 0;
else
_library = lib->get_instance_id();
// Update model UVs because atlas size is defined by the library // Update model UVs because atlas size is defined by the library
update_cube_uv_sides(); update_cube_uv_sides();
} }
VoxelLibrary *Voxel::get_library() const { VoxelLibrary *Voxel::get_library() const {
Object *v = _library.get_ref(); if(_library == 0)
return NULL;
Object *v = ObjectDB::get_instance(_library);
if (v) if (v)
return Object::cast_to<VoxelLibrary>(v); return Object::cast_to<VoxelLibrary>(v);
return NULL; return NULL;

View File

@ -92,7 +92,7 @@ protected:
//Ref<Voxel> set_xquad_geometry(Vector2 atlas_pos); //Ref<Voxel> set_xquad_geometry(Vector2 atlas_pos);
private: private:
WeakRef _library; ObjectID _library;
// Identifiers // Identifiers
int _id; int _id;