Problem with IMAGECREATE() and IMAGEDESTROY

General FreeBASIC programming questions.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Problem with IMAGECREATE() and IMAGEDESTROY

Postby Cpcdos » Jul 17, 2013 12:23

hi !
( i'm French )
i have un problem if i use IMAGEDESTROY (by IMAGECREATE)

Example if i use IMAGEDESTROY myimage in my .exe program, on certain x86 computers tested with Intel Atom , I3 I5 and I7, the program crash!!

If i remplace
IMAGEDESTROY myimage
by
myimage = 0
the program work perfectly
But myimage = 0 does not clean memory...
so memory increase more in more if i reuse IMAGECREATE and system crash ...

There are a another solution for avoid IMAGEDESTROY ?
pestery
Posts: 493
Joined: Jun 16, 2007 2:00
Location: Australia

Re: Problem with IMAGECREATE() and IMAGEDESTROY

Postby pestery » Jul 17, 2013 13:21

Is your program small enough to post in the topic? It would help a lot if we could see your code, or even just a small section of it near IMAGECREATE and IMAGEDESTROY. Also, IMAGEDESTROY should not cause your program to crash if used correctly.

For the moment I just have two suggestions.
If your IMAGEDESTROY command is in a function that could accidently be called more than once then try using.

Code: Select all

If myimage <> 0 Then
   IMAGEDESTROY myimage
   myimage = 0
EndIf

The other idea is to add PRINT myimage : SLEEP after the IMAGECREATE and before the IMAGEDESTROY. That way you can see if the myimage pointer has changed somewhere between the two PRINT commands. If the pointer is different then your program would crash.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: Problem with IMAGECREATE() and IMAGEDESTROY

Postby Cpcdos » Jul 17, 2013 14:00

Ho yes thank you very much !

I have remplaced IMAGEDESTROY by your code

Code: Select all

If myimage <> 0 Then
   IMAGEDESTROY myimage
   myimage = 0
EndIf


I think well it is because imagedestroy was executed 2 times

Thank !! :D
fxm
Posts: 9014
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Problem with IMAGECREATE() and IMAGEDESTROY

Postby fxm » Jul 17, 2013 14:16

Also, be careful to always call 'ImageCreate' when a graphic mode is already initialized, else a null pointer is returned and ... :-(
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: Problem with IMAGECREATE() and IMAGEDESTROY

Postby Cpcdos » Jul 17, 2013 14:19

Yes yes no problem, thank you! :)
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Re: Problem with IMAGECREATE() and IMAGEDESTROY

Postby podvornyak » Jul 17, 2013 14:43

Cpcdos wrote:There are a another solution for avoid IMAGEDESTROY ?

Slage Hammer Method

Code: Select all

dim shared as uinteger window_width = 800, window_height = 600, window_depth = 32

screenres window_width, window_height, window_depth

' screen buffer
dim shared as uinteger ptr frame_buffer
frame_buffer = screenptr

' image 100X100
dim as uinteger ptr frame_image = new uinteger[100*100]
for i as integer = 0 to 9999
   frame_image[i] = rgb(rnd*255,rnd*255,rnd*255)
next i

' put function
sub put_image (x as uinteger, y as uinteger, x_size as uinteger, y_size as uinteger, image as uinteger ptr)
   for i as integer = 0 to y_size-1
      for j as integer = 0 to x_size-1
         ' simple segmetation fault evasion.
         if y+y_size < window_height and x+x_size < window_width then
            *(frame_buffer+(y+i)*window_width+x+j) = *(image+i*x_size+j)
         else
            ' crop algorythm here
         end if
      next j
   next i
end sub

screenlock
put_image (520, 311 , 100, 100, frame_image)
put_image (230, 111 , 50, 200, frame_image)
put_image (10, 10 , 10, 10, frame_image)
screenunlock
sleep
delete[] frame_image
end
akumadantai
Posts: 34
Joined: Apr 03, 2012 13:09

Re: Problem with IMAGECREATE() and IMAGEDESTROY

Postby akumadantai » Jul 17, 2013 16:32

also, make sure not to destroy the image (delete) before you use it.

Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests