[futurebasic] Re: RELEASERESOURCE

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 1998 : Group Archive : Group : All Groups

From: Jamin <benjamen@...>
Date: Sun, 19 Jul 98 18:04:20 +1000
>
>Scenario 2: "without"
>---------------------
>1. You get a handle to the resource: h& = FN GET1RESOURCE(_"PICT", 3000)
>2. During the course of subsequent processing, the resource happens
>   to get purged.  But the Resource Manager _remembers_ the handle.
>3. This time, you do NOT call RELEASERESOURCE.  You've commented
>   it out of your code.
>4. Some time later, you call h& = FN GET1RESOURCE(_"PICT", 3000)
>   again.  The Resource Manager looks in its resource map and
>   says "ah!  I already have a handle that's associated with that
>   resource," and it returns that handle to your program.  The
>   problem is, it's a handle to a non-existent block.  The Resource
>   Manager does _not_ allocate a new block, and does _not_ load
>   the resource back into memory for you.  It just returns the
>   old handle.  If you now call some routine that assumes there's
>   an actual block of data associated with that handle, then you're
>   _lucky_ if you merely get unexpected program behavior.  More
>   likely, you'll crash.
>

Rick,
I am a little confused, as far as I know GET1RESOURCE will never return 
an invalid handle (other than Zero), and according to "Think Reference" a 
purged resource will always have its master pointer set to zero.  Here is 
a short demo that _should_ fail as per your Scenario above?

Jamin


**** WARNING - demo requires MacsBug to be installed ****

RESOURCES "Resource file with Purgable PICT ID 128"

WINDOW 1

' Load and display PICTure
myResource& = FN GETRESOURCE(_"PICT",128)
PRINT "Errors:";FN RESERROR,SYSERROR
PRINT "Resource Handle: ";myResource&
LONG IF myResource& > 0
    PICTURE (5,70),myResource&

    ' Check for yourself that it is loaded in our heap
   CALL DEBUGSTR(";HD PICT")
END IF

' Make OS dump it
IgnoreResult& = MEM(_MaxAvail)
CLS

' Check for yourself that it is dumped
CALL DEBUGSTR(";HD PICT")

' Load and display PICTure
myResource& = FN GETRESOURCE(_"PICT",128)
PRINT "Errors:";FN RESERROR,SYSERROR
PRINT "Resource Handle: ";myResource&
LONG IF myResource& > 0
    PICTURE (5,70),myResource&

    ' Check for yourself that it is re-loaded in our heap
   CALL DEBUGSTR(";HD PICT")
END IF

END