Hello and thanks for responses,

at the moment the function that inits the global list items and variables is 
storing around 50 * 20 strings, the chunk is allocated at application startup 
and is set at 8kb (8192) as there was mention somewhere of granularity of the 
nand.

therefore is not writing outside the malloc.

When the pointer being used to store either the locked MemHandle or the MemPtr 
is displayed as a 4 byte numeral (in other words the address location) after 
being declared and also just before the items are written to the chunk, they 
are the same.


Still have not found a solution. The desk accessory cannot use globals, as no 
desk accessories can, although there are a few methods around this, Ftr memory, 
prefs, a typedefed global struct, etc.

something like so :
in included header

typedef struct psuedo_globals {
  // form
  Int16 X;
  Int16 Y;
  Int16 W;
  Int16 H;

  // pen detection
  RectangleType P[MaxPenDetectAreas];

  // DeskHandler
  Coord x_DIFF; // form move coords
  Coord y_DIFF;
  Coord x_STRT;
  Coord y_STRT;
  Coord x_SAV;
  Coord y_SAV;

  // etc., etc...

  }psuedo_globals;



then in the main.c for the desk accessory would be something like:


//  •••••••••••• •••••••••••• ••••••••••••
//start 
Int8 start(void){Deskmain(); return 0x00;




// ••••••••••••••••••••••••••
// InitGlobals
psuedo_globals*
InitGlobals(void) {return(MemPtrNew(sizeof(psuedo_globals)));}


// ••••••••••••••••••••••••••
// Deskmain
void
Deskmain(void)
{
// check for duplicate invocation
UInt32 feature;
if (!(FtrGet(DeskCrID, 0, &feature))) return;
  else FtrSet(DeskCrID, 0, 0);



******* this is first malloc, having no problems with this *****

// init & check global vars 
Err err;
if (!(GLB=InitGlobals())) return;



**** these are some of global struct members that need initing ****
GLB->scrn_H=FrmGetWindowHandle(FrmGetActiveForm());
GLB->firstPass=true;
GLB->initWin=true;
GLB->timerOn=false;             // TIMER FOR FORM MOVE
GLB->fm=0;                      // FORM MOVE

GLB->nameFLG=0;
GLB->listCLOSE=0;
GLB->listFLG=0;

GLB->FTR=NULL;
GLB->HND=NULL;
GLB->PTR=NULL;

GLB->listScrBuffer=NULL;
GLB->LCurrent=0;
GLB->LTotalItems=0;
GLB->flickFlag=0;
GLB->checkSpeedOn=0;


****** then some startup functions, no problems with these ******
// fonts 
Init_Fonts();

// prefs
LoadPrefs(GLB);

// form bounds
RectangleType frm;
FormPtr frm_P=FrmInitForm(MainDeskForm);
frm.topLeft.x=GLB->X;
frm.topLeft.y=GLB->Y;
frm.extent.x=GLB->W;
frm.extent.y=GLB->H;
GLB->desk_H=FrmGetWindowHandle(frm_P);
WinSetBounds(GLB->desk_H, &frm);

// pen detect rectangles
Init_PenDetects(GLB);

// fields
RectangleType fld_R;
GLB->F1P=(FieldType *) FrmGetObjectPtr (frm_P,   
  FrmGetObjectIndex (frm_P, FLDNameID));
GLB->F2P=(FieldType *) FrmGetObjectPtr (frm_P,   
  FrmGetObjectIndex (frm_P, FLDDescID));

FldSetFont (GLB->F1P, FS4);
FldSetFont (GLB->F2P, FS3);

fld_R.topLeft.x=GLB->P[name].topLeft.x+3;
fld_R.topLeft.y=GLB->P[name].topLeft.y+2;
fld_R.extent.x=GLB->P[name].extent.x-4;
fld_R.extent.y=GLB->P[name].extent.y-4;
FrmSetObjectBounds(frm_P, 
  FrmGetObjectIndex (frm_P, FLDNameID), &fld_R);

fld_R.topLeft.x=GLB->P[desc].topLeft.x+4;
fld_R.topLeft.y=GLB->P[desc].topLeft.y+5;
fld_R.extent.x=GLB->P[desc].extent.x-9;
fld_R.extent.y=GLB->P[desc].extent.y-9;
FrmSetObjectBounds(frm_P, 
  FrmGetObjectIndex (frm_P, FLDDescID), &fld_R);

// init  PINS
GLB->trig1=0;
GLB->trig2=0;
UInt32 PINver;
UInt16 get;
Err PINerr=FtrGet(pinCreator,pinFtrAPIVersion,&PINver);
if (!PINerr&&PINver) {
  err=FrmSetDIAPolicyAttr(frm_P, frmDIAPolicyCustom);
  GLB->trig1=(PINGetInputTriggerState()==
    pinInputTriggerEnabled);
  err=PINSetInputTriggerState(
    pinInputTriggerDisabled);
  GLB->trig2=(SysGetOrientationTriggerState()==
    sysOrientationTriggerEnabled);
  err=SysSetOrientationTriggerState (
    sysOrientationTriggerDisabled);
  get=PINGetInputAreaState();
  if (get==0) err=PINSetInputAreaState(0);
  if (get==1) err=PINSetInputAreaState(1);
  }

// turn off system-sound (pen-taps outside form)
UInt16 vol1, vol2, vol3, sndOff=0;
SndGetDefaultVolume(&vol1, &vol2, &vol3);
SndSetDefaultVolume(&sndOff, &sndOff, &sndOff);

// set form
FrmSetActiveForm(frm_P);
EvtFlushPenQueue();


****** then this is the second malloc, for list items that are inited in 
another function called during normal event loop processing,
using FtrPtrNew at the moment as that 
works if not released.************

// allocate list malloc  // 8192
err=FtrPtrNew(DeskCrID, 0x01, 2048, &GLB->FTR);
if (err) 
  {
  txtDialogue(0x00, 50, "FtrPtrNew err", 0);
  }


// handler
Eventloop(GLB);


// cleanup

// restore system sound
SndSetDefaultVolume(&vol1, &vol2, &vol3);



***** this is remmed out as not doing so induces resets *****
// release list
//err=FtrPtrFree(DeskCrID, 0x01);    
if (err) 
  {
  txtDialogue(0x00, 50, "FtrPtrFree err", 0);
  }


// save prefs
SavePrefs(GLB);

// delete form
FrmEraseForm(frm_P);
FrmDeleteForm(frm_P);

// unload (reset) custom fonts
FntSetFont(0x00); FontPtr fp=FntGetFontPtr();
for (int i=0;i<maxFonts;i++) { FontID font=FS1+i;
  FntDefineFont(font, fp); }

// reset InputTrigger
UInt32 PINver;
Err PINerr=FtrGet(pinCreator,pinFtrAPIVersion,&PINver);
if (!PINerr&&PINver) {
  if (GLB->trig1) 
    err=PINSetInputTriggerState(
      pinInputTriggerEnabled);
  if (GLB->trig2) 
    err=SysSetOrientationTriggerState(
      sysOrientationTriggerEnabled);
  }



// release global chunk here
err=MemPtrUnlock(GLB);
err=MemPtrFree(GLB);

// release ftr
if  (!(FtrGet(DeskCrID, 0, &feature)))
  FtrUnregister(DeskCrID, 0);

}

any help appreciated
regards
Darren




-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to