Loop broken when calling a dll from a type method

Archives Forums/BlitzMax Bug Reports/Loop broken when calling a dll from a type method

Klaas(Posted 2009) [#1]
Hi

I encountered a strange problem. Cant figure out what this is!
The Line "webcam[currentWebcam].grapFrame()" breaks the loops. cframe just does not stop when reaching ccf. None of the local var names are present anywhere else. when i comment out the line, everything works fine

	For Local cstep:Int = 0 To cfgFramesPerTurn -1
		For Local cframe:Int = 0 To cfgFramesPerShot -1
			'next line will break the loops
			webcam[currentWebcam].grapFrame()
			image = LoadImage(webcam[currentWebcam].lastFrame)
			DrawImage(image, 0, 0)
			Flip()
			SetStatusText(winMain, "Step: " + cstep + "/" + cfgFramesPerTurn + "  |  Frame" + cframe + "/" + ccf)
		Next
		Cls()
		Flip()
	Next



now more wiered is ... this works fine. Insertung fixed values for the loop do work.
	For Local cstep:Int = 0 To 5-1
		For Local cframe:Int = 0 To 5-1
			'next line will break the loops
			webcam[currentWebcam].grapFrame()
			image = LoadImage(webcam[currentWebcam].lastFrame)
			DrawImage(image, 0, 0)
			Flip()
			SetStatusText(winMain, "Step: " + cstep + "/" + cfgFramesPerTurn + "  |  Frame" + cframe + "/" + ccf)
		Next
		Cls()
		Flip()
	Next



cfgFramesPerTurn, cfgFramesPerShot are both global vars but arnt touched in any way while doing the loop. GrapFrame calls an dll and copies a pixmap.
I will mail code to support if required.


Klaas(Posted 2009) [#2]
I have done some more research.

The problem is not the dll. Calling the dll directly from the loop will work. Doing the call by a type method not. I've implemented a timer and it is clearly visible that cframe is equal to cfgFramesPerShot after a while.

Inserting a ...
If cframe = cfgFramesPerShot - 1 Then Exit
... does fix my problem, but still its weird!


marksibly(Posted 2009) [#3]
Hi,

Are you using the correct calling convention with the DLL?

If it's stdcall and you're using cdecl or something, it will result in stack errors/crashes etc.