Problem with ImagesCollide

BlitzPlus Forums/BlitzPlus Programming/Problem with ImagesCollide

Mikle(Posted 2003) [#1]
Hi everybody,

I have a problem with ImagesCollide: sometimes it gives error "Illegal memory address".

It is big problem for us, because this error occurs more or less regulerely in 10% of runs.

As I understand, it is somehow related to video hardware. Does anybody know how to deal with such problem?

Thanks if you can hekp.

Mikle.


_PJ_(Posted 2003) [#2]
I have had this problem, when testing a Blitz creation in debug mode. It usually occurred when I had exited the application by closing the window rather than letting it stop/end 'naturally'

Perhaps some memory is used and certain data is residual in a pagefile or something making less free space for when you re-run the app.


Mikle(Posted 2003) [#3]
Thanks,

The problem is that the error occurs in non-debug mode, when I check intersection of mouse cursor with an image. When the program is simple enough and image collision checking is not used heavily, everything works fine. But when some threshold of complexity is crossed, the error occurs. Either this is related to disk swap or video memory usage, I don’t know.

When I worked with 8-mb video card under Win95 the problem appeared much more frequently.

Now I have GeForce2-64 and work under XP, but the error appears from time to time. I work on Duron-630 with 128 Mb.

Mikle.


cyberseth(Posted 2003) [#4]
I believe that this problem comes up if you make lots of images at run-time which is quite inefficient. It is also due to the way that Blitz3D and Blitz2D handled images in memory. BlitzPlus has a "flag" for images which allows them to be more stable, if you really must create and free images on the fly at runtime. Like I said though, I don't recommend it.


maverick69(Posted 2003) [#5]
probably you try to check a image that isnt avaible / is not loaded. i think this error occurs if you check for an image that isnt avaible.

do you check through serveral images in a loop? have you deleted some images before?


Tiger(Posted 2003) [#6]
Click here!


Mikle(Posted 2003) [#7]
To Jochen Heizmann:

Thank you.

Yes, I check through several images in a loop. Say, I have 20 buttons with complex form (e.g. animal figures) on the scene and I need to activate one of them (change its frame) when the cursor touches it. In this case, as you understand, I cannot use ImagesOverlap command.

Usually I try to avoid ImagesCollide command, but in some cases it is not possible.

Maybe, I have to formulate the problem clearly.

=================

When used in cycle, ImagesCollide command SOMETIMES causes memory allocation error while working with THE SAME set of images.
All images are “correct” (that is, exist and are created outside of checking loop).

When many images are loaded into memory (say, 20-30 mb of graphics), probability of the error increases.

Usually this error occurs in one of 10-20 runs of the same program, on old video cards (2-3 year old) more probably than on new ones (say, GF2 with 64 mb). It seems that on professional video cards, specially designed for 2d-applications (Matrox), this problem does not occur (but I am not sure).

=================

Mikle.


Mikle(Posted 2003) [#8]
To cyberseth:

Sorry, what do you mean under “runtime”? Sometimes I do create a lot of rotated images on fly, but not in the main program cycle. Or you meant that ALL images should be only loaded?

By the way, you touched the point I always wanted to clear up (about the way that Blitz3D and Blitz2D handle images). Could you tell me where I can get some information about it and what are the advantages of Blitz+ in this sense?

Thanks,

Mikle.


cyberseth(Posted 2003) [#9]
I mean that you should always refrain from creating images during the game loop if possible, rather than at the beginning of the game. Either use one image over and over again for "temporary" images. (Where you'd create an image, do stuff to it, then free it. Instead use the same image in memory over and over again.) And load all media at the beginning.

Check the BlitzPlus docs for LoadImage, LoadAnimImage and CreateImage commands:

LoadImage( filename$[,flags] )

Where flag is of the following:
1 : managed
2 : dynamic
4 : scratch

"dynamic" is the type used in Blitz3D/2D and is the fastest type of image to write to directly. But it's often a bit volatile and can disappear if you create and free lots of images during the game loop. "managed" images get round this by being very stable and they also don't free up if you change graphics modes. The downside is that they are slower. "scratch" images are stored in RAM instead of VRAM so they are the slowest by far, but as they don't take up any VRAM you can have more of them.

Personally I think it's a bit odd that the flags should be 1, 2, and 4 instead of 3. You only use ONE flag, not a combination.

One last thing. You shouldn't use ImagesCollide for checking the mouse over buttons. You only want to check if the "tip" of the mouse is over a button, not the whole mouse image. So instead, you should use ImageRectCollide(image, x, y, 0, MouseX(), MouseY(), 1, 1)


Mikle(Posted 2003) [#10]
To cyberseth,

I usually do just as you say. As I have found, the problem is not in ImagesCollide, but in multi-framed images. See my <a href=http://www.blitzbasic.com/bbs/posts.php?topic=20054 target=_blank> post to BlitzBugs forum.

Thanks for tip with mouse. I’ll use it when possible.

Mikle.