Fast Pointer

Blitz3D Forums/Blitz3D Programming/Fast Pointer

Yue(Posted 2012) [#1]
Graphics3D 800, 600, 32, 2
camara% = CreateCamera()

cubo% = CreateCube() PositionEntity cubo%,0,0,10

Local img% = LoadAnimImage("image1.png", 256,256,0,13)
Global Imagen
Global  Imagen2
Global tuco%
Function Cargarimagen( imagenn%=0 )
	
	If Imagen% = 0
		Imagen% = LoadImage ("Yue.bmp") ; 150 megas
		ScaleImage Imagen%,.01,.01
		Imagen2 = LoadImage("Yue2.bmp") ; 210 Megas.
		
		
	End If 
		If Imagen<> 0 tuco% = True 
	
			
	Return Imagen%
End Function
ThreadFunctionPointer = FunctionPointer()
Goto skip
peco = Cargarimagen()  
.skip

Thread = CreateThread (ThreadFunctionPointer, im)

Repeat 
	
        ;RenderWorld 
	RenderWorld 
	t#=t+.5
	
	If t = 13 Then t =  0
	If tuco = False 
		DrawImage img%, 0,0,Rand(0,t)
	Else 
		FreeImage img%
	End If 
	
	;TurnEntity cubo%,0,0,1
	
	If tuco% = True
		
		DrawImage Imagen2%, 0, 0
		DrawImage Imagen%, 100,100
	End If 
	
	Flip
Until KeyDown(1)


Still not sure about using Fast Load Pointer to the first level of resources, it seems that everything works fine, however my lack of experience I have fear that may happen in the application errors when used by third party users.

Any advice.

The above example loads two big realmenta images and displays a progress bar animated frames.


Yasha(Posted 2012) [#2]
Yes, you can't safely share resources between threads using simple Blitz globals and objects. The whole point is that since the threads are running at the same time, it's entirely possible for a global to be being read and set at the same instant, and therefore end up with something containing half-set corrupted data. It's probably fine in this specific case, but you shouldn't use it in general.

You should consider:

-- only delegating to threads tasks that do not require shared data
-- using a timer-based communication system (hard)
-- using HeapAlloc to create thread-shared objects which can then be thread-locked with HeapLock (you'll need to read up on Windows Heaps, and also how to use Locks, in order to do this)


The other FastPointer functionality is safe (assuming you use it safely!).


Yue(Posted 2012) [#3]
In the case of the two images that really are great, I've noticed a problem, and that is if the app is running on windows screen mode, if the user hits the close button on the title bar of the app crashes or stops responding.

I'm trying to close the thread by Blitzclose.dll and seems to work well.


AppTitle "Yue"



; First parameter is the scancode to fake, the second is the window name
InstallCloseHandler(72, "Yue")




Graphics3D 800, 600, 32, 2
camara% = CreateCamera()

cubo% = CreateCube() PositionEntity cubo%,0,0,10

Local img% = LoadAnimImage("image1.png", 256,256,0,13)
Global Imagen
Global  Imagen2
Global tuco%
Function Cargarimagen( imagenn%=0 )
	
	
	
	
	If Imagen% = 0
		Imagen% = LoadImage ("Yue.bmp") ; 150 megas
;		ScaleImage Imagen%,.01,.01
		;Imagen2 = LoadImage("Yue2.bmp") ; 210 Megas.
		
		
	End If 
		If Imagen<> 0 tuco% = True 
	
			
	Return Imagen%
End Function
ThreadFunctionPointer = FunctionPointer()
Goto skip
peco = Cargarimagen()  
.skip

Thread = CreateThread (ThreadFunctionPointer, im)

Repeat 
	
	If KeyHit(72)  
		FreeThread(Thread)
		End 
	EndIf
	
	
	
        ;RenderWorld 
	RenderWorld 
	t#=t+.5
	
	If t = 13 Then t =  0
	If tuco = False 
		DrawImage img%, 0,0,Rand(0,t)
	Else 
		FreeImage img%
		If IsThread(Thread) Then FreeThread(Thread)
	End If 
	
	;TurnEntity cubo%,0,0,1
	
	If tuco% = True
		
		;DrawImage Imagen2%, 0, 0
		DrawImage Imagen%, 100,100
	End If 
	
	Flip
Until KeyDown(1)
UnInstallCloseHandler()
If IsThread(Thread) Then FreeThread(Thread)


Last edited 2012