New Type EXCEPTION_ACCESS_VIOLATION

BlitzMax Forums/BlitzMax Beginners Area/New Type EXCEPTION_ACCESS_VIOLATION

BLaBZ(Posted 2010) [#1]
I'm trying to create the second instance of a type and when it hits this line

Local bPixmapData:PixmapData = New PixmapData


I receive the "EXCEPTION_ACCESS_VIOLATION" notification.

I believe it has something to do with memory access.. lol

all help is much appreciated :)


Brucey(Posted 2010) [#2]
You need to provide more code... what's PixmapData and what does it do in its New() method?


BLaBZ(Posted 2010) [#3]
I'm basically trying to take an Image Sequence and turn it into a Image Strip,

The code attempts to take the first image in the sequence, get the sequence number, then checks to see if the next file in the sequence exists, if it does, it acquires its pixmap pixel data, then it attempts to draw all of the acquired pixmap data to a single pixmap

Here's a link to a zip file containing a small image sequence
http://bizzybud.com/files/comp1_00029.zip


	''''TEMPORAREY'''''
	Local FirstImagePath:String = "C:\Users\Ben\Desktop\AnimStrip\test\Comp 1_00000.png"
	Local SavePath:String = "AAA.png"
	'''''''''''''''''''
	
	'breakdown file name structure
	Local filename:String = StripDir(FirstImagePath)
	'find how many in the . is
	Local var1:Int = Instr(filename, ".")
	'remove the .png
	Local step1:String = Left(filename, var1 - 1)
	'find how many in the _ is
	Local var2:Int = Instr(step1, "_")
	'remove everything before _
	Local sequenceNumber:String = Right(step1, Len(step1) - var2)
	Local sequenceName:String = Left(step1, var2)


	'find out how many images are in the sequence
	Local newNumber:String = sequenceNumber
	Local Quit:Int = 0
	While Not Quit = 1
	
		'check if file exists
		If FileType(ExtractDir(FirstImagePath) + "/" + sequenceName + newNumber + ".png") = 1
			'acquire pixmap data
			PixmapData.Acquire(LoadPixmap(ExtractDir(FirstImagePath) + "/" + sequenceName + newNumber + ".png"))
		Else
			Quit = 1
		End If
		
		'construct the name of the file to check
		newNumber:String = String(Int(newNumber) + 1)
		While Len(newNumber) < Len(sequenceNumber)
			newNumber = "0" + newNumber
		Wend
	Wend
	SavePixmapPNG(PixmapData.Draw(), SavePath, 9)



'''''''''''''''''''''''''''''''''''''''''''''''
'pixmapdata object holds all pixmap information	
Type PixmapData

	Global List:TList=CreateList()
	Global Total:Int'number of pixmaps
	
	Field Width:Int
	Field Height:Int
	
	Field Pixels:Int[9999,9999]
	
	'Acquire the information of a pixmap
	Function Acquire(thePixmap:TPixmap)
		Local bPixmapData:PixmapData = New PixmapData
		ListAddLast(PixmapData.List,bPixmapData)
		PixmapData.Total = PixmapData.Total + 1
		bPixmapData.Width = PixmapWidth(thePixmap)
		bPixmapData.Height = PixmapHeight(thePixmap)
		For x:Int=0 To PixmapWidth(thePixmap)-1
			For y:Int=0 To PixmapHeight(thePixmap)-1
				bPixmapData.Pixels[x,y] = ReadPixel(thePixmap,x,y)
			Next
		Next
	End Function
	
	'draw the data of each acquired pixmap and return the new pixmap
	Function Draw:TPixmap() 
		Local newPixmap:TPixmap =CreatePixmap(10,10,PF_RGBA8888)'PixmapData.Width*PixmapData.Total,PixmapData.Height,PF_RGBA8888)
		Local xStart:Int = 0
		For aPixmapData:PixmapData = EachIn PixmapData.List
			For x:Int=1 To aPixmapData.Width
				For y:Int=1 To aPixmapData.Height
					WritePixel(newPixmap,xStart+x,y,aPixmapData.Pixels[x,y])
				Next
			Next
		Next
		Return newPixmap
	End Function	

End Type



Jesse(Posted 2010) [#4]
I believe the problem is how you are reading the pixels from the pixmap.
the first pixle across in a pixmap is 0 and the last pixel is width-1. In your case you are skeeping the first pixel and trying to read a pixel that does not exists. the same goes for pixels down.

Try running your program in debug mode. it'll give you a more detail description of the error.


BLaBZ(Posted 2010) [#5]
When I change it to..

For x:Int=1 To PixmapWidth(thePixmap)
	For y:Int=1 To PixmapHeight(thePixmap)
		bPixmapData.Pixels[x,y] = ReadPixel(thePixmap,x,y)
	Next
Next


I get the error message "Unhandled Exception:Pixmap coordinates out of bounds"


Zeke(Posted 2010) [#6]
For x:Int=1 To PixmapWidth(thePixmap)

change to:
For x:Int=1 Until PixmapWidth(thePixmap)

or
For x:Int=1 To PixmapWidth(thePixmap)-1

and pixels positions strart from 0


Foppy(Posted 2010) [#7]
Applying what Jesse and Zeke said to the draw function, this
For x:Int=1 To aPixmapData.Width
	For y:Int=1 To aPixmapData.Height
		WritePixel(newPixmap,xStart+x,y,aPixmapData.Pixels[x,y])
	Next
Next

should be this:
For x:Int = 0 To aPixmapData.Width-1
	For y:Int = 0 To aPixmapData.Height-1
		WritePixel(newPixmap,xStart+x,y,aPixmapData.Pixels[x,y])
	Next
Next



Brucey(Posted 2010) [#8]
-1, -1, -1... it always looks so.. untidy to me...
For x:Int=0 Until aPixmapData.Width
	For y:Int=0 Until aPixmapData.Height
		WritePixel(newPixmap,xStart+x,y,aPixmapData.Pixels[x,y])
	Next
Next

using a zero index and Until look much more readable. (according to my own opinion)


jondecker76(Posted 2010) [#9]
wow, i just learned something new!

So are you saying that Until used with a for loop automatically subtracts 1 from the next variable??


Brucey(Posted 2010) [#10]
Yes... so you tend to use it in a loop based on a zero index (like a BlitzMax array, for example).


Czar Flavius(Posted 2010) [#11]
I hardly ever use To these days!


ima747(Posted 2010) [#12]
Once I got Until into my thick head I've never looked back... makes loops SOOOOOO much more readable.