glmax2D DeleteTex error

Started by meems, March 18, 2018, 14:11:52

Previous topic - Next topic

meems

I'm getting a strange index out of bounds error when I try to load an image
traces to

module : glmax2D
function : DeleteTex
line 100 : dead_texs[n_dead_texs]=name


this during my function that's creating about 30 small images by drawing them and grabbing them from the display.
currently trying to isolate the error to give u the minimal code to cause the error.
The comments say DeleteTex is not 'thread safe', don't know if this is something to do with it.

meems

Code (blitzmax) Select
Graphics 1024,768

Global imagelist:TImage[200]

Global blockart:TImage[10]

Global wall1:TImage=LoadImage("coldwall.png")
Global wall2:TImage=loadimage2("wall2.png")
Global gene:TImage=LoadImage2("gene.png")
Global blocko:TImage=LoadImage2("blocks2\blocko.bmp")
Global blockc:TImage=LoadImage2("blocks2\blockc.bmp")
Global blocks:TImage=LoadImage2("blocks2\blocks.bmp")
Global blockq:TImage=LoadImage2("blocks2\blockq.bmp")
Global blockx:TImage=LoadImage2("blocks2\blockx.bmp")
Global blockd:TImage=LoadImage2("blocks2\blockd.bmp")
Global blockb:TImage=loadimage2("blocks2\blockb.bmp")

Global btarray:btemplate[100]
create_block_mix()
Global noi ' number of images ( not strictly true if arrows don't appear in list )


Function loadimage2:TImage(fn$)

imagelist[noi]=LoadImage(fn$)
noi=noi+1
Return imagelist[noi-1]

End Function



Type btemplate

Field ch

Method create_block_image()

Local blockart:TImage

blockart=LoadImage("blocks2\blockart"+ch+".bmp")

DrawImage blockart,0,0
GrabImage blockart,0,0

imagelist[noi]=CreateImage(30,30,1,dynamicimage=1)
DrawImage blockart,0,0
DrawImage imagelist[noi],0,0
GrabImage imagelist[noi],0,0

noi=noi+1

End Method

End Type



Function create_block_mix()
' this function is then sent to create block image, to make a random mix of blocks for this game
Local i,j
Local bt:btemplate

For i=2 To 9 '  < -------------- ******** change this to 8 and problem goes away ********

bt=New btemplate
j=Rand(0,6)
bt.Ch=j
btarray[3*(i-2)]=bt
bt.Create_block_image()

bt=New btemplate
bt.ch=Rand(j+1,7)
btarray[3*(i-2)+1]=bt
bt.Create_block_image()

bt=New btemplate
bt.ch=Rand(j+1,8)
btarray[3*(i-2)+2]=bt
bt.Create_block_image()
Next

End Function


I've stripped the bug code down to 83 lines. But it needs some images to work with. Trying to use the debugger doesn't work because with the debugger on the problem vanishes

Henri

Hi,

I might be missing something here, but the example doesn't crash or create any errors that are obvious.

-Henri
- Got 01100011 problems, but the bit ain't 00000001

meems

#3
I get unhandled exception , attempt to index array beyound array length.
at line 41
blockart=LoadImage("blocks2\blockart"+ch+".bmp")
which goes to DeleteTex in glmax2D

bcc[ng] version 0.87
bmk 3.16 mt-win32-x86 gcc 050100 x4 cpu
gcc,g++ 5.10

the debugger is on, but when i use the debugstop to step thru the program, it finds no error

at the point of error, ch=4

If I change line 41 to
blockart=LoadImage("blocks2\blockart"+4+".bmp")

then there is no error on that line, but then the error occurs at line 46
imagelist[noi]=CreateImage(30,30,1,dynamicimage=1)
which goes to DeleteTex in glmax2D

meems

have u created some images with correct filenames for the code to use?

col

For testing I'd rearrange the globals so that appear in the execution path before they are being used.

For example I'd try putting the noi variable at the top so that its guaranteed to be initialized before its used in any function. I'd do the same for all of those Globals - just for the sake of testing. Then I'd print out the variable that is indexing the array(s) as they are indexing them... just to make sure the indexes are in fact correct.
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

col

#6
I'd also change

blockart=LoadImage("blocks2\blockart"+ch+".bmp")
to
blockart=LoadImage("blocks2\blockart"+ch+".bmp", DYNAMICIMAGE)

and also

imagelist[noi]=CreateImage(30,30,1,dynamicimage=1)
to
imagelist[noi]=CreateImage(30,30,1,dynamicimage)

as the documentation for GrabImage states...
QuoteOnly images created with the DYNAMICIMAGE flag can be grabbed.

Using DYNAMICIMAGE=1 is a comparison which will compare the value DYNAMICIMAGE to 1 and return a boolean result.
DYNAMICIMAGE is defined as the value of 8, which is then compared to the value 1 resulting in the boolean value of False. BlitzMax uses as 0 ( zero ) as a numerical value for False. This means that your code doesn't actually set the DYNAMICIMAGE flag as you are setting the flags parameter to 0 instead of 8.

Hope it helps
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

meems

hi col, i eagerly implemented your suggestions , hoping it'd fix this problem. no luck with the DYNAMICIMAGE correction, or the global noi placed above the function that uses it. :(

the problem is elsewhere. It looks to me like its particular to my setup, perhaps a bug in my hardware or my drivers.

col

Have you tried it with the legacy BlitzMax to see if it makes any difference?
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

meems

I'm poking around in the glmax2d code, trying to get more info on the bug
The bug path is
Loadimage -> Load -> Create -> Delete -> DeleteTex -> Delete -> DeleteTex

But I don't see Delete called in the glmax2d Create function
Code (blitzmax) Select

Function Create:TImage( width,height,frames,flags,mr,mg,mb )
Local t:TImage=New TImage
t.width=width
t.height=height
t.flags=flags
t.mask_r=mr
t.mask_g=mg
t.mask_b=mb
t.pixmaps=New TPixmap[frames]
t.frames=New TImageFrame[frames]
t.seqs=New Int[frames]
Return t
End Function


I don't get how the program reaches Delete

meems

I get no bug in legacy blitzmax

col

#11
I also get the same results in both NG and legacy ( that is 'error in ng' and 'no error in legacy' ). I'd guess this is an issue with NGs management of the textures (IF its different ). I'll take a look. I assume you're using the latest version of NG or a very late version?
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

meems

bcc[ng] version 0.87
bmk 3.16 mt-win32-x86 gcc 050100 x4 cpu
gcc,g++ 5.10

dunno if thats the latest, I dl'ed it about a month ago.
Glad someone else is getting the error. thx for looking into this.

col

#13
You can fix the issue using this DeleteTex function code inside the glmax2d.bmx file:-
Remember to backup the original or make a note of the change in case this fix doesn't stand up to scrutiny.


edit:- I've raised the issue on the github repo so that Brucey will see this thread post.
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Henri

I get no error in legacy or NG.

@meems
You are running older version. Download newest release version from https://github.com/bmx-ng/bmx-ng/releases.

-Henri
- Got 01100011 problems, but the bit ain't 00000001