create_object_replace.c
snippets · 1.9 KB · 2010-03-30
create_object replacement that stops "missing objects" problems.
Download « Back to the snippets list
// ************************************************************* //
// * This is just a simple setup for create_object to stop any * //
// * future problems with 'missing objects' I know many people* //
// * Have issues with it, so this is the fix.. it is alittle * //
// * time consuming. So Please, do not do this if you are lazy* //
// ************************************************************* //
// *This requires a function from my log_string replacement* //
in db.c
find create_object (the function) and replace it with this.
OBJ_DATA *__create_object( OBJ_INDEX_DATA *pObjIndex, int level, int vnum, const char *file, const char *ifunction, int line)
Now, down in where it says if(pObjIndex == NULL), replace that whole thing with this.
if ( pObjIndex == NULL )
{
nlogf( "Create_object: NULL pObjIndex: vnum %d, file: %s, function: %s, line: %d", vnum, file, ifunction, line );
exit( 1 );
}
This will effectively log what file, function, and line of code caused the 'missing object' and the vnum of said-object.
Now, in merc.h or proto.h, whatever you have, replace your create_object with the following.
OD * __create_object args( ( OBJ_INDEX_DATA *pObjIndex, int level, int vnum, const char *file, const char *ifunction, int line) );
#define create_object( pObjIndex, level, vnum) __create_object(pObjIndex, level, vnum, __FILE__, __FUNCTION__, __LINE__ )
Now here is the 'fun' part if you will.
Every single call to create_object, must now have a third variable, the objects vnum. An example of this would be be like this.
pObj = create_object(get_obj_index(OBJ_VNUM_SCHOOL_SWORD), 1, OBJ_VNUM_SCHOOL_SWORD);
The only other option i can see to this, is to remove the call to pObjIndex from create_object, and have the get_obj_index
done inside of the create_object function itself, which, as fun as that sounds, it honestly isn't. I didn't do that change
because, well, this one was easier, atleast in my opinion.
Enjoy