Perdida recurso en Preview

User avatar
Carles
Posts: 1149
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona
Been thanked: 7 times
Contact:

Perdida recurso en Preview

Post by Carles »

Hola,

Adjunto ejemplo

Code: Select all | Expand

#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 ...
Image

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

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

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

Charly,

Gracias por el ejemplo.

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

Code: Select all | Expand

   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
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

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: Select all | Expand

*-------------------------
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
User avatar
Carles
Posts: 1149
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona
Been thanked: 7 times
Contact:

Re: Perdida recurso en Preview

Post by Carles »

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
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
Posts: 1149
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona
Been thanked: 7 times
Contact:

Re: Perdida recurso en Preview

Post by Carles »

A,

La perdida se inicia en el Valid de la ventana

Code: Select all | Expand

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
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
Posts: 1149
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona
Been thanked: 7 times
Contact:

Re: Perdida recurso en Preview

Post by Carles »

Antonio,

Parece que con estos cambios ya funciona bien

Linea del valid de la window

Code: Select all | Expand

      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: Select all | Expand

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
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

Rectifico:

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

:-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

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: Select all | Expand

  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
User avatar
carlos vargas
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: Perdida recurso en Preview

Post by carlos vargas »

Antonio
es correcto esto?

Code: Select all | Expand

     
      oBmp:End()
   next
 


no seria mejor despues de del next finalizar el objeto bitmap?

Code: Select all | Expand

     
   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)
User avatar
Antonio Linares
Site Admin
Posts: 42513
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 31 times
Been thanked: 73 times
Contact:

Re: Perdida recurso en Preview

Post by Antonio Linares »

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
Post Reply