Object Locking

Greetings all,

I’m creating a plugin and storing Dictionary references as REALobjects. I’m treating them similar to a REALstring where I’m locking the reference to my object in the setter function, but when my Xojo code refers back to it, it’s crashing. Am I doing something wrong?

static void AreasDictSetter(REALobject dict){ REALUnlockObject(AreasDict); AreasDict = dict; REALLockObject(AreasDict); };

don’t check.
This must be your coding style:

AreasDict always has a locked reference.

Don’t forget to release it in destructor.

Christian, there’s no destructor in a module. I presume Xojo just destroys all in a module when the app quits?

I better list my semi-complete module code so it can be critiqued:

REALproperty myModuleProperties[] = { { "", "AreasDict", "Dictionary", REALScopePublic, (REALproc)AreasDictGetter, (REALproc)AreasDictSetter }, };

static REALobject AreasDict;

static REALobject AreasDictGetter(void); static void AreasDictSetter(REALobject dict);

static REALobject AreasDictGetter(void){ return AreasDict; };

static void AreasDictSetter(REALobject dict){ REALUnlockObject(AreasDict); AreasDict = dict; REALLockObject(AreasDict); };

Found the problem. The answer was in the Complete Module example.

When returning an object I was not locking it, thereby leaving a null pointer which is BAD!! Changing my getter code to the following solves the problem, which is only for properties within a module:

static REALobject AreasDictGetter(void){ REALLockObject(AreasDict); return AreasDict; };