aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-05-03 22:05:24 -0400
committerkwolekr <kwolekr@minetest.net>2015-05-03 22:19:35 -0400
commit5b237b4d94cc3fa4a95f951654dfbe37dcf2e2f9 (patch)
tree44c81991d6d4956e1ca4cadb7ac90ad17ae78e19 /src/mapgen.cpp
parent5704fb36d208e250490e6fb56268e75e0b9b3290 (diff)
downloadminetest-5b237b4d94cc3fa4a95f951654dfbe37dcf2e2f9.tar.gz
minetest-5b237b4d94cc3fa4a95f951654dfbe37dcf2e2f9.tar.bz2
minetest-5b237b4d94cc3fa4a95f951654dfbe37dcf2e2f9.zip
ObjDefManager: Set replacement object's handle info after calling set()
Make gamedef optional when constructing an ObjDefManager Add note about object ownership
Diffstat (limited to 'src/mapgen.cpp')
-rw-r--r--src/mapgen.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/mapgen.cpp b/src/mapgen.cpp
index d8eb8068a..1de7fca81 100644
--- a/src/mapgen.cpp
+++ b/src/mapgen.cpp
@@ -434,7 +434,7 @@ void GenerateNotifier::getEvents(
ObjDefManager::ObjDefManager(IGameDef *gamedef, ObjDefType type)
{
m_objtype = type;
- m_ndef = gamedef->getNodeDefManager();
+ m_ndef = gamedef ? gamedef->getNodeDefManager() : NULL;
}
@@ -471,7 +471,16 @@ ObjDef *ObjDefManager::get(ObjDefHandle handle) const
ObjDef *ObjDefManager::set(ObjDefHandle handle, ObjDef *obj)
{
u32 index = validateHandle(handle);
- return (index != OBJDEF_INVALID_INDEX) ? setRaw(index, obj) : NULL;
+ if (index == OBJDEF_INVALID_INDEX)
+ return NULL;
+
+ ObjDef *oldobj = setRaw(index, obj);
+
+ obj->uid = oldobj->uid;
+ obj->index = oldobj->index;
+ obj->handle = oldobj->handle;
+
+ return oldobj;
}