1. Button caption Bitmap crashes

Hi friends,

Bellow has a little code to illustrates a bug
with caption button showing bitmap.

This is a simple code, but I am getting crashes in
others more important codes.

If you do a simple look or better, if you run the 
code any times it works fine, no problem.

But if the bitmap showed in the button is changed
a great number of times, the program crashes.

If you kindly go to test this, please 
before run the code, create under the 
same directory 3 files with bitmap files and 
rename him to "save.bmp", "savecolor.bmp" and
"savecolor.bmp" . The code need thats files
to fill the button face.

I get hem in appropriate sizes to button's faces
and I can send to you thats bitmaps by e-mail

To do changes easy, the code provides bitmap
replaces with mouse movements under the console 
code and shows the changes number. 

So, run this application and move your mouse under
the window and the button's bitmap will be 
replaced a lot.

After 1100 replaces,  more and less, the button 
no more shows anyone bitmap and sometimes lock 
all another applications and need reboot the 
computer.

If you use a very large bitmap them the crash
will happen in other way and more quickly.

Please, any idea????

Best Regards.

Sergio Gelli - Brasil.

-- System Milleniun, Euphoria 2.5 and last win32lib
--The code


without warning
include win32lib.ew
integer sinaliza,nn,tt         -- p/variar fonte do botao SAVE
constant MAIN = create (Window        , "",    0, 10, 10, 250, 160, 0 ),
         EDT = create( EditText       , "", MAIN,  2,  2, 200,  25, 0 ),
         SAVE =createEx( PictureButton, "", MAIN,  2, 30,  53,  44, 0, 0 ),
         OVERTIME = 2 --MLE + 1
sinaliza =0 nn=1 tt=1
object VOID
setTimer(MAIN, OVERTIME, 1000 ) -- Timer do cursor ???
-----------------------------------------------------------------------------
procedure runOVERTIME(integer event, integer zxx, integer zxy, integer shift )
-- enable smooth over-scrolling to occur
-------------------------	
 integer x, y 
 sequence mouse, screen
 -- relogio no CAPTION -----------------------------------------------------
 sequence TimeAndDate, StrWeek,theTime, font
 integer week,day,seconds,minutes,hours
 TimeAndDate = date() -- returns both time and date info
 day = TimeAndDate[3]
 hours = TimeAndDate[4]
 minutes = TimeAndDate[5]
 seconds = TimeAndDate[6]
 week = TimeAndDate[7]
 StrWeek={"Dom ","Seg ","Ter ","Qua ","Qui ","Sex ","Sab "}
 StrWeek=StrWeek[week]
 -- display the new clock time: 
 theTime=sprintf("%02d-%s%02d:%02d:%02d",{day,StrWeek,hours,minutes,seconds})
 TimeAndDate =theTime
 setText(MAIN,TimeAndDate &repeat(32,115-length(TimeAndDate)) & theTime)
 ------------------- fim relogio no CAPTION ----------------------------------
 if tt=1 then
  tt=0
  return
 end if	
 tt=0
	setText(EDT,sprintf( "BMP changes %d times \n",{nn}))
	if event!=WM_MOUSEMOVE then
VOID=message_box(sprintf( "sinaliza = %d BMP changes %d times
  \n",{sinaliza,nn}),
           "Mensagem !", MB_ICONEXCLAMATION  + MB_TASKMODAL)
  return
 end if 
  nn+=1 	
 if sinaliza=0 then  -- 
  setBitmap( SAVE, "Save.bmp" )
  setHint (SAVE,"sinaliza=1")
  sinaliza=1
 elsif sinaliza=1 then
  sinaliza=2
  setBitmap( SAVE, "SaveCOLOR.bmp" )
  setHint (SAVE,"sinaliza=0")
 elsif sinaliza=2 then
  setHint (SAVE,"Salvo")
  setBitmap( SAVE, "saved.BMP" )
  sinaliza=0

-- killTimer( MAIN, OVERTIME ) -- vendo se para de dar erro em setFont
 end if 
end procedure
-------------------------------------------------------------------	
onMouse[MAIN] = routine_id("runOVERTIME")
procedure ontimer(integer timer_id)
 tt=1
 runOVERTIME(1,2,3,4)
end procedure
------------------------------------------------------------------
-- set up call back for the various timer events
onTimer[MAIN] = routine_id("ontimer")
--runOverScroll()
WinMain(MAIN,Normal)

new topic     » topic index » view message » categorize

2. Re: Button caption Bitmap crashes

Sergio Gelli wrote:
> 
> 
> Hi friends,
> 
> Bellow has a little code to illustrates a bug
> with caption button showing bitmap.
> 
> This is a simple code, but I am getting crashes in
> others more important codes.
> 
> If you do a simple look or better, if you run the 
> code any times it works fine, no problem.
> 
> But if the bitmap showed in the button is changed
> a great number of times, the program crashes.

The problem is that your system is running out of memory, because each time you
call setBitmap() with the *name* of a bitmap file, it is loaded into RAM again
and the previous RAM used by the bitmap is not released.

I suggest you do it differently.

First, in the program's initialization code, load the three bitmaps like this
...

 bmSave = loadBitmapFromFile("Save.bmp")
 bmSaveCOLOR = loadBitmapfromFile("SaveCOLOR.bmp")
 bmSaved = loadBitmapFromFile("Saved.bmp")

then replace the setBitmap calls you now have with ...

 setBitmap(SAVE, bmSave) 

instead of 

 setBitmap(SAVE, "Save.bmp") 


and do the same with the other setBitmap calls.

Doing it this way, you only load each bitmap once from disk, and you don't run
out of RAM.

-- 
Derek Parnell
Melbourne, Australia
irc://irc.sorcery.net:9000/euphoria

new topic     » goto parent     » topic index » view message » categorize

3. Re: Button caption Bitmap crashes

Tanks Mr. Derek, now my program works with 
repainting bitmap very times and don't crashes.

But in another intance is necessary change this 
bitmap with a great number of different files.

I thing the better to do is realise each section
of memory ( if it's possible ), but I don't know 
how do it.
Please, would you send an idea about this?

Best regards.

Sérgio Gelli - Brasil

new topic     » goto parent     » topic index » view message » categorize

4. Re: Button caption Bitmap crashes

Sergio Gelli wrote:
> But in another intance is necessary change this 
> bitmap with a great number of different files.
> 
> I thing the better to do is realise each section
> of memory ( if it's possible ), but I don't know 
> how do it.
> Please, would you send an idea about this?

  atom bmSave

  -- Allocate RAM and place bitmap file into it.
  bmSave = loadBitmapFromFile("Save.bmp")

  -- Release the RAM used by the bitmap
  deleteObject(bmSave)

-- 
Derek Parnell
Melbourne, Australia
irc://irc.sorcery.net:9000/euphoria

new topic     » goto parent     » topic index » view message » categorize

5. Re: Button caption Bitmap crashes

Very thanks Mr. Derek, I will try it.

Sérgio Gelli - Brasil

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu