FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Perdida recurso en Preview
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Perdida recurso en Preview
Posted: Tue Dec 16, 2014 10:29 AM
Hola,

Adjunto ejemplo

Code (fw): Select all Collapse
#include 'fivewin.ch'

STATIC oWnd 

*--------------
FUNCTION Main()
*--------------
    LOCAL oBar, oBtn, oBtnRpt, oMenu, oRptDsg
    
    DEFINE WINDOW oWnd TITLE 'Version: ' + FWVERSION

        DEFINE BUTTONBAR oBar SIZE 30, 30 _3D OF oWnd
        DEFINE BUTTON oBtn OF oBar NAME '' ACTION Test_Prn()

    ACTIVATE WINDOW oWnd
    
    
RETU NIL


*-------------------------
STATIC FUNCTION Test_Prn()
*-------------------------

    LOCAL oPrn := PrintBegin( 'test' , .F., .T.,, .f., .f. )
    

    PAGE
       oPrn:Say( 20, 20, "This 1 is a test in Landscape" )
    ENDPAGE
    PAGE
       oPrn:Say( 20, 20, "This 2 is a test in Landscape" )
    ENDPAGE
    PAGE
       oPrn:Say( 20, 20, "This 3 is a test in Landscape" )
    ENDPAGE

    ENDPRINT

RETU NIL


Cuando ejecuto el preview y lo cierro (quizas lo deba hacer mas de una vez ...) la barra de botones aparece negra, como si perdiera algun brush, recurso... Alguien le ha pasado y ha encontrado una solución ?

Antes de ejecutar preview ...


Despues de cerrar el preview...
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 10:40 AM
Charly,

Gracias por el ejemplo.

Lo que acabo de observar es que si sólo imprimimos una hoja entonces el problema no ocurre:

Code (fw): Select all Collapse
    PRINT oPrn PREVIEW
    
       PAGE
          oPrn:Say( 20, 20, "This 1 is a test in Landscape" )
       ENDPAGE

    ENDPRINT


Lo que no se me ocurre es que relación puede tener el número de hojas con que se destruya el brush...
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 10:46 AM
Otro detalle curioso es que si definimos así la barra de botones, el bug no aparece:

DEFINE BUTTONBAR oBar SIZE 30, 30 _3D OF oWnd 2007
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 11:41 AM
Esta claro que el problema se produce por un decremento excesivo del contador del brush de la buttonbar.

Con esta línea añadida, ya no se produce el error:

Code (fw): Select all Collapse
*-------------------------
STATIC FUNCTION Test_Prn()
*-------------------------

    PRINT oPrn PREVIEW
    
       PAGE
          oPrn:Say( 20, 20, "This 1 is a test in Landscape" )
       ENDPAGE

       PAGE
          oPrn:Say( 20, 20, "This 1 is a test in Landscape" )
       ENDPAGE

    ENDPRINT
    
    oWnd:oBar:oBrush:nCount++  // nueva!

RETU NIL
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 11:45 AM

Antonio,

Uhmmm.... no se no se,... :roll:

El decremento del contador se ha de hacer en el preview, no ?

Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 12:20 PM
A,

La perdida se inicia en el Valid de la ventana

Code (fw): Select all Collapse
If( ! Empty( ::oImageListPages ), ::oImageListPages:End(),),;
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 1283
Joined: Fri Feb 10, 2006 02:34 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 12:31 PM
Antonio,

Parece que con estos cambios ya funciona bien

Linea del valid de la window

Code (fw): Select all Collapse
      VALID        ( ::oWnd:oIcon := nil       ,;
                     ::oFont:End()             ,;   
                     ::oCursor:End()           ,;
                     ::oMeta1:End()            ,;
                     ::oMeta2:End()            ,;
                     ::oHand:End()             ,;   
                     If( Empty( ::oImageList )      ,, ( ::oImageList:End(), ::oImageList := nil ) ),;                   
                     If( Empty( ::oImageListPages ) ,, ( ::oImageListPages:End(), ::oImageListPages := nil ) ),;             
                     ::oWnd := nil             ,;
                     ::oDevice:oPreview := nil ,;                    
                     ::lExit := .T. )


Método BuildListView()

Code (fw): Select all Collapse
METHOD BuildListView() CLASS TPreview

   local nSizeH, nSizeV, oBmp, n, aPrompts := {}
   local aBmp

   if ::oDevice:nHorzRes() > ::oDevice:nVertRes()
     nSizeH = 100
     nSizeV = 80
   else
     nSizeH = 80
     nSizeV = 100
   endif
   
   ::oImageListPages = TImageList():New( nSizeH, nSizeV )

   aBmp := Array( Len( ::oDevice:aMeta ) )
   
   for n := 1 to Len( ::oDevice:aMeta )
      aBmp[n] := TBitmap():Define()
      aBmp[n]:hBitmap := PageBitmap( ::oDevice:aMeta[ n ], nSizeH, nSizeV )
      ::oImageListPages:Add( aBmp[n] )
      Aadd( aPrompts, AllTrim( Str( n ) ) )
   NEXT  
   
   ::oLvw = TListView():New( 33 - If( ::oWnd:oTop:IsKindOf( "TBAR" ), 6, 0 ),;
                             0, aPrompts, { | nPage | ::GoPage( nPage ) }, ::oWnd,;
                             ,, .T.,, nSizeH + 45, ScreenHeight() - ;
                             If( ::oWnd:oBar != nil, ::oWnd:oBar:nHeight() - 2,;
                             ::oWnd:oTop:nHeight() ) - ;
                             If( ::oWnd:oMsgBar != nil, ::oWnd:oMsgBar:nHeight(),;
                             ::oWnd:oBottom:nHeight() ) - 38 )
   ::oLvw:SetImageList( ::oImageListPages )
   ::oLvw:bRClicked = { || If( ::oLvw:nLeft == 0,;
                               ::oLvw:nLeft := ::oWnd:nWidth - ::oLvw:nWidth - 30,;
                               ::oLvw:nLeft := 0 ) }   

return nil


Podeis verificarlo ?
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
HIX -> https://github.com/carles9000/hix
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 05:39 PM

Charly,

Ahora funciona bien! :-)

Cómo lo has encontrado ? Estoy intentando adivinar como esta relacionado ese cambio con el error :-)

Gracias!!!

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 05:42 PM

Estabamos usando un handle de bitmap no válido aqui:

::oImageListPages:Add( ... )

pero que relación tiene eso con un brush ? :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 05:46 PM

A ver,

Esto no puede funcionar bien:

::oImageListPages:Add( aBmp[n] )

Porque se espera un objeto bitmap

Sigo sin ver la relación con el oDevice que ya no se destruye en el VALID, y menos con el brush :-S

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 05:48 PM

Rectifico:

aBmp[ n ] es un array de objetos bitmaps...

:-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 06:16 PM

Charly,

me quito el sombrero :-)

Increible como lo has cazado :-)

La línea que causaba todo el problema era:

  oBmp = TBitmap():Define()

Porque crea un control y se llama al Método SetColor() desde el método Define() y SetColor() crea un brush ;-)

me falta por entender el porque si estaba fuera del buble, y además no se destruía, tenía que incrementar un contador de brush y no decrementarlo...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 06:31 PM
El problema viene del método Define() de la Clase TBitmap, que al derivar de TControl y al llamarse al método SetColor() desde él pues crea un brush.

Lo primero a arreglar es quitar esta llamada en el método Detault() de la clase TBitmap:

// ::SetColor( GetSysColor( COLOR_WINDOWTEXT ), GetSysColor( COLOR_BTNFACE ) )

Si un objeto TBitmap solo se va a usar para mantener un handle de un bitmap no tiene sentido que establezca colores y cree brushes.

Una vez hecho eso, el código de METHOD BuildListView() CLASS TPreview podemos dejarlo asi:

Code (fw): Select all Collapse
   oBmp = TBitmap():Define()
   ::oImageListPages = TImageList():New( nSizeH, nSizeV )

   for n := 1 to Len( ::oDevice:aMeta )
      oBmp:hBitmap := PageBitmap( ::oDevice:aMeta[ n ], nSizeH, nSizeV )
      ::oImageListPages:Add( oBmp )
      Aadd( aPrompts, AllTrim( Str( n ) ) )
      oBmp:End()
   next


Asi solo creamos un objeto TBitmap. Con uno es suficiente para liberar el handle del bitmap que estamos cargando en oBmp:hBitmap al hacer oBmp:End()

Con sólo eso funciona bien :-)

Mil gracias de nuevo Charly! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 08:45 PM
Antonio
es correcto esto?
Code (fw): Select all Collapse
      
      oBmp:End()
   next


no seria mejor despues de del next finalizar el objeto bitmap?
Code (fw): Select all Collapse
      
   next
   oBmp:End()

o incluso la creacion del bitmap en el ciclo next?

no estoy muy claro en esto.
salu2
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Perdida recurso en Preview
Posted: Tue Dec 16, 2014 09:00 PM

Carlos,

Es necesario llamar al método End() para que libere el handle que hay en la DATA hBitmap.

Tiene que estar dentro del bucle, y la creación del objeto oBmp fuera del bucle, asi solo creamos uno y lo reusamos.

regards, saludos

Antonio Linares
www.fivetechsoft.com