Function pointers

Blitz3D Forums/Blitz3D Programming/Function pointers

Noobody(Posted 2009) [#1]
So, since I'm currently messing around with Lua, I got interested, if it's possible to find out the pointer that points to a user-defined Blitzbasic function.

It should be possible, since every time, when Blitz calls a function, it pushes the current instruction pointer onto the stack, so that the called function is able to return to this point.
So, imagine, you wrote a function in C in combination with inline assembler, that is called by your Blitz function right after the function itself is called.
The C function then reads the instruction pointer, which was pushed by Blitz onto the stack, and gets a value that points to the instruction right after the Blitz function calls the C function.
Everything you have to do now is to subtract a small value from this instruction pointer and you get... the pointer to the Blitz function!

I tried it out and it actually works - but there're still problems.
It seems that Blitz uses a different calling convention when calling Blitz functions than the _stdcall convention.
That leads to a memory access violation, when the Blitz function tries to return to its caller.

Global Pointer

Test()
CallFunction( Pointer ) ;<--- This is the C function that calls the Blitz function by it's pointer
WaitKey()
End

Function Test()
	Pointer = FunctionPointer() ;<--- This is the C function that returns the function pointer
	
	Print "This works! Function pointer: " + Pointer

	Return  ;<--- This works fine when the function is called by Blitz
	;however, when the DLL calls this function, 'Return' leads to a MAV
End Function



I found a way to avoid this, but it's not as clean as I want it to be.
I rewrote 'CallFunction' so it remembers from where it was called (using the instruction pointer on the stack).
The Blitz function then calls a C function 'ReturnInt' instead of 'Return', when it's called by the DLL.
'ReturnInt' then jumps back to the instruction pointer saved by 'CallFunction'.
This actually works, but it leaves a really messy stack behind, which leads to a stack overflow, if you let the DLL call the Blitz function too often.

So, is there anyone out there who knows, how a Blitz function has to be called or which convention it uses?
It would be very nice to get the function pointers to work, especially for DLLs that require Callback functions or for example Lua, which would call user-defined Blitz functions, when used in the script.

My current test code in Blitz:
Global Pointer, Call

Print Test()
CallFunction( Pointer )
WaitKey()
End

Function Test()
	Pointer = FunctionPointer()
	
	Print "Works! Call no. " + Call
	
	Call = Call + 1
	
	If Call = 1 Then
		Return 5
	Else
		ReturnInt( 5 )
	EndIf
End Function


C++ - Code:
#define BBEXPORT extern "C" _declspec(dllexport)

void (__stdcall *JumpFunction)(void);

BBEXPORT int __stdcall FunctionPointer() {
	unsigned int StackPosition, Adress;

	__asm {
		mov StackPosition,esp
		mov esp,ebp
		add esp,4
		pop Adress
		mov esp,StackPosition
	}

	return Adress - 8;
}

BBEXPORT int __stdcall CallFunction( int (__stdcall *B3DFunction)(void) ) {
	unsigned int StackPosition;

	__asm {
		mov StackPosition,esp
		mov esp,ebp
		add esp,4
		pop JumpFunction
		mov esp,StackPosition
	}

	return B3DFunction();
}

BBEXPORT void __stdcall ReturnInt( int Value ) {
	__asm {
		mov eax,[Value]
	}

	JumpFunction();
}



Warner(Posted 2009) [#2]
This is a very interesting read. Thank you. So, at this point, this is like a special form of Gosub ? You could use it not only for functions, but you can use it at any point in your program, right ?
I have not much experience with C++, which compiler do you use ? My guess would be you should use cdecl, since userlib functions should be declared that way as well.


Noobody(Posted 2009) [#3]
So, at this point, this is like a special form of Gosub ? You could use it not only for functions, but you can use it at any point in your program, right ?


Yes, that's right.
You could use it at any point in your program, save the pointer and use this pointer to jump to that piece of code later.

Thank you for the hint with Gosub - this was the solution for my problem!
It seems that when you create a label, save the pointer to this label and jump from the DLL to that label, you're able to jump back with 'Return'.

So, the following code works:
Global Pointer
GoSub Test

CallFunction( Pointer )
WaitKey()
End

.Test
	Pointer = FunctionPointer()
	Print "Hello, I am called from both Blitz and C!"
Return ;<---- With GoSub instead of Function, 'Return' works without a Memory Access Violation


The only problem ist that you can't use either types or string variables, when the code is called from the DLL.
But with a bit of a workaround, you can get this to work too.

Global Pointer, FirstCall = True
GoSub Test

CallFunction( Pointer )
WaitKey()
End

.Test
	Pointer = FunctionPointer()
	
	If FirstCall Then
		FirstCall = False
		Return
	Else
		B3DFunction()
	EndIf
Return

Function B3DFunction()
	StringVar$ = "This function can handle strings without a problem!"
	
	Print StringVar
End Function

Meaning, if you let the code after the label call a regular Blitz function, everything works fine.

So, with this DLL, we finally have the feature of function pointers in Blitz :)
A bit messy though, but working.

I have not much experience with C++, which compiler do you use ?

I use Visual C++ 2008 Express Edition (long name :/).

My guess would be you should use cdecl, since userlib functions should be declared that way as well.

I already tried all kinds of calling conventions, but none would work.
And my Userlibs.txt says "All functions MUST use the _stdcall calling convention.", so I ended up with that.


jfk EO-11110(Posted 2009) [#4]
It's only a guess: The Return Adress is stored on the Stack, just like the parameters. The function caller writes everything to the stack (first the return address, then the parameters), then calls the function. The function reads "down" the stack, including and finally the return adress (filo). I still have no idea where the result is stored (eg a=test(b)), esp. because the result may also be a string or float... At the end the Stackpointer might have to be corrected, so there won't be any stack under- or overflow.

But as I said in the beginning: this was only a guess. From somebody who didn't touch assembler for years.


ZJP(Posted 2009) [#5]
Hi,

This my own version with PowerBasic.

PowerBasic DLL. Very short DLL ;-)
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Pointeur de fonction / Gosub-Return
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#COMPILER PBWIN 9
#COMPILE DLL
'
FUNCTION FunctionPointer ALIAS "FunctionPointer" () EXPORT AS LONG
    DIM StackPosition AS LONG
    DIM Adress AS LONG

      !  mov StackPosition,esp
      !  mov esp,ebp
      !  add esp,4
      !  pop Adress
      !  mov esp,StackPosition

    FUNCTION = Adress - 8
END FUNCTION

SUB GOSUB_EXTRN ALIAS "Gosub_Extrn" (BYVAL Adresse AS LONG PTR) EXPORT
    GOSUB DWORD Adresse
END SUB


Decls
.lib "BLITZ_FP.DLL"

FunctionPointer%()    : "FunctionPointer"
Gosub_Extrn(Adresse%) : "Gosub_Extrn"


Blitz3D Test

Global V$      ; No Pb with string. works well in Debug or Release Mode
Global Pointer ; Init pointer
Gosub Test            ; Call From Blitz3D
Gosub_Extrn(Pointer) ; Call From/By the DLL
WaitKey()
End

.Test
	Pointer = FunctionPointer()
        v$="Pointer value is " + Pointer
	Print "Hello, I am called from both Blitz and C!"
        Print V$
Return 


This is a good way for external timer/thread calls ;-)
Next step? Maybe :

THREAD_MASTER_INIT
TRDx=THREAD_CREATE(Pointer)
STATUS=THREAD_STATUS(TRDx)
THREAD_CLOSE(TRDx)
THREAD_MASTER_CLOSE

Thx for the idea ;-)

JP
Edit : It would be interesting to use the other cores (with a C2D/C2Q and SetThreadAffinityMask ) for threads ;-)


ZJP(Posted 2009) [#6]
The FreeBasic version ;-)

'
FUNCTION FunctionPointer ALIAS "FunctionPointer" ()  AS UInteger Export
    DIM StackPosition AS UInteger
    DIM Adress AS UInteger
    Asm
      	mov [StackPosition],esp
      	mov esp,ebp
      	Add esp,4
      	pop [Adress]
      	mov esp,[StackPosition]
    End Asm
    Return Adress - 8
END FUNCTION

SUB GOSUB_EXTRN ALIAS "Gosub_Extrn" (BYVAL Adresse AS UInteger PTR) EXPORT
    Asm Call [Adresse]
END SUB


The .decls

.lib "BLITZFB_FP.DLL"

FunctionPointer%()    : "FunctionPointer@0"
Gosub_Extrn(Adresse%) : "Gosub_Extrn@4"



ZJP(Posted 2009) [#7]
Thread for Blitz.
New post here http://www.blitzbasic.com/Community/posts.php?topic=84325

JP


MikhailV(Posted 2009) [#8]
Cool! And my old experiments - http://fastlibs.com/temp/ThreadsAndPointers.zip (Ņan work in a debug-mode!)

Some functions from decls-file:
FunctionPointer% ()
DataPointer% ()
LabelPointer% ()
ArrayPointer% ()
VarPointer% ()
TypePointer% (type*)

CallFunction% (FunctionPointer%)
CallFunctionVarInt% (FunctionPointer%, value%)
CallFunctionVarFloat% (FunctionPointer%, value#)
CallFunctionVarType% (FunctionPointer%, value*)

GotoPointer% (LabelPointer%)
GosubPointer% (LabelPointer%)

CreateThread% (FunctionPointer%, Value%)
FreeThread% (Thread%)
PriorityThread% (Thread%, Priority%)
PauseThread% (Thread%)
ResumeThread% (Thread%)
WaitThread% (Thread%, Timeout%)
IsThread% (Thread%)

...


*EDIT: Archive updated (+1 new example)


ZJP(Posted 2009) [#9]
Hahaha. Good technique. He had to think. I appreciate.
MyFunctionFirstPointer = FunctionPointer()
	Goto skip
	MyFunctionFirst()
	.skip

or
MyFirstLabelPointer = LabelPointer()
	Goto skip
	Goto MyFirstLabel
	.skip

JP

PS : "Example_WindowCallback.bb" is a empty file :-)


MikhailV(Posted 2009) [#10]
Thanks :)

Example_WindowCallback.bb not empty!
Contains important warning:

"DON'T USE function pointers for window-callbacks, it's incorrect for Blitz3D.
Blitz3D generate window messages in self code and your callback goto into infinite loop (and stack-overflow MAV after)!"

:D


ZJP(Posted 2009) [#11]
New version.

More "elegant". (MikhailV ;-) )
But, Impossible to use Global and Debug mode :-(
Blitz source

; Init The pointer. Do not change this structure
;++++++++++++++++++++++++++++++++++++
Pointer = GetPointer()
	Goto skip
	Goto Test
	.skip
;++++++++++++++++++++++++++++++++++++

While Not KeyDown(1)
	a=a+1
	Print "This is the main " + A
	Delay 100
	If a=30 Then Gosub_Ex pointer
Wend
End 

.Test
	Print "Hello, I am called from the DLL"
	For i=1 To 1000
		Delay 1
		Print ">>>> CALL BY THE DLL "+ i
    Next
Return 


PowerBasic dll code
#COMPILER PBWIN 9
#COMPILE DLL
'
FUNCTION GetPointer ALIAS "GetPointer" () EXPORT AS LONG
    DIM StackPosition AS LONG
    DIM Adress AS LONG

      !  mov StackPosition,esp
      !  mov esp,ebp
      !  add esp,4
      !  pop Adress
      !  mov esp,StackPosition

    FUNCTION = Adress + 8
END FUNCTION

SUB Gosub_Ex ALIAS "Gosub_Ex" (BYVAL Adresse AS LONG PTR) EXPORT
    GOSUB DWORD Adresse
END SUB



Yasha(Posted 2009) [#12]
@MixailV

This question is a bit redundant, but are we free to use your DLL?


MikhailV(Posted 2009) [#13]
@Yasha: Free for all :)


ZJP(Posted 2009) [#14]
Hi,

Your lib works in debug mode now. Cool.

JP


MikhailV(Posted 2009) [#15]
@ZJP: Yeeesss :)


Rroff(Posted 2009) [#16]
This is really really neat - using fastpointer - I can create a common framework for my applications - and then call standard init, main, exit, etc. functions without having to implicitly name them :) great job guys.

Also great for stuff like individual entity events when handled through a generic entity handler.

EDIT: Not to forget the threading potential - thats a real stroke of genius.


Bobysait(Posted 2012) [#17]
@MikhailV :
Any way to get the source of fastpointer dll ? (at least the basis : FunctionPointer and CallFunction)


Guy Fawkes(Posted 2012) [#18]
Why the heck do I get in trouble when posting in old threads, but THIS guy posts in here, and its O! Well here ya go friend. Here's some help. :<

Last edited 2012


Adam Novagen(Posted 2012) [#19]
Funny, I don't notice anyone offering to help him; the first post after his is your complaint. And you're right, he shouldn't be posting in an old thread, he should 1) use Google and 2) failing that, start a new thread for his question.


Bobysait(Posted 2012) [#20]
Guys, as I'm not a "newbie" I maybe deserve a little more respect than 2 people not glad with someone who resurect an old topic because all he needs is related to this topic ^^

I need the help of MikhailV, and all I need is related to this topic.
And you're not administrator or moderator on blitzbasic's forum ...
Sorry but : I don't care about your opinion unless you really answer the question/problem I posted

Last edited 2012


Guy Fawkes(Posted 2012) [#21]
u can stop with the smart alec comments anytime now. or I will continue haunting ur threads. so BACKOFF, and have a nice day. :) Thank u! :)


Bobysait(Posted 2012) [#22]
If (for any reason you imagine) you don't want to respect me, really, I don't care, but, at least, respect this topic which is not mine ^^

and once again, sorry but :
I have no time to waste on your delirium, so maybe we can go back to serious things now ?!

Last edited 2012


Guy Fawkes(Posted 2012) [#23]
Or maybe u can quit being a jerk long enough to figure out ur problem, then leave us alone :) Good day! :) *Tips top hat*

Last edited 2012


Ross C(Posted 2012) [#24]
There's nothing wrong with bumping an old thread, if your specifically requiring information within that thread. If he was to start a new topic, he'd need to copy and paste all the relevant information into the new thread, or provide a link to the old thread. Which people will click on and read anyway.

Don't worry Bobysait. He's just antsy because you bumped a thread above his.


ando(Posted 2012) [#25]
Bobysait has done nothing wrong......and is in fact showing a high level of patience. :)


Bobysait(Posted 2012) [#26]
whatever
maybe u can quit being a jerk long enough to figure out ur problem

I don't know if being a "jerk" would have allowed me to solve such a problem but, in fact, I did
At least, I solved the second part of the problem by writing the c++ code of a "CallFunction" wich supports as many arguments as I needed. (wich finally allows me to get my script engine working)

I still don't understand how MikhailV has done to get the function pointers ... All I can get is Label pointers and some virtual/local function pointers that are not persistant :/
At the moment, my engine can work in assossiation to the FunctionPointer function from FastPointer dll, but I would really want it to work with its own FunctionPointer (The aim is to export a single dll for my whole project and skip FastPointer.dll)

I'll wait for MikhailV's answer as he did it (and its function also works with debugger enabled while mine doesn't)


ps : I don't really worry about Thundros ;)
He is probably very young, by time he'll probably learn how to behave on a programming forum :)

...
I hope

And thanks for the support ;)


Ross C(Posted 2012) [#27]
And! I BET you he doesn't even own a tophat! I bet you!


Or maybe u can quit being a jerk long enough to figure out ur problem



Ha, That's rich!


then leave us alone :) Good day! :) *Tips top hat*



Us? Your own your own buddy ;)


Guy Fawkes(Posted 2012) [#28]
Nope, bobbysait is a jerk, and he knows it. period. end of story. Thundros out


Ross C(Posted 2012) [#29]
Why is he a jerk?


Bobysait(Posted 2012) [#30]
bobbysait is a jerk, and he knows it

All I know is that you are annoying although useless in this topic (wich one you probably don't understand a word by the way)

So, happy for me, I don't waste time thinking about people who come and pretend I am a "douche" or a "jerk" or else just because I posted something in a relevant place :)


Adam Novagen(Posted 2012) [#31]
Thundros out
Don't I wish.

In an effort to make things productive again, Bob, I apologize for my earlier post; I've been a bit on edge recently due to various things, and really didn't need to be so curt.


stayne(Posted 2012) [#32]
Thundros out


*spits coffee everywhere and cheers*


Guy Fawkes(Posted 2012) [#33]
Out of this topic, u numbskulls ><


Naughty Alien(Posted 2012) [#34]
..what does it mean 'Thundros' anyway??..


Guy Fawkes(Posted 2012) [#35]
A mix between Andross from Starfox and Thunder? I dont know o.O I just made it up


stayne(Posted 2012) [#36]
Thundros how old are you? I want to see a picture of you.


Guy Fawkes(Posted 2012) [#37]
Im not showing u a picture of me. Then u can post it all over the net. Not that I would mind the fame. But no.


Naughty Alien(Posted 2012) [#38]
..why not ? Im just curious, nothing else ? ..


Guy Fawkes(Posted 2012) [#39]
No. I dont trust u. Nor do I trust ANYONE hardly.


ando(Posted 2012) [#40]
.....

Last edited 2012


Guy Fawkes(Posted 2012) [#41]
Im very secure about myself. so im sorry. i must pass that up.


Naughty Alien(Posted 2012) [#42]
..why dont you trust me..I have shown myself in few threads here, where all other people show themselves..there is nothing wrong to share such things among fellow coders..


Guy Fawkes(Posted 2012) [#43]
Dont take it personally. I dont trust anybody but myself or my family. And ur petty peer pressure does NOT work on me. :) Good day :)


Rob the Great(Posted 2012) [#44]

Im very secure about myself. so im sorry. i must pass that up.


The lady doth protest too much, methinks.


Yasha(Posted 2012) [#45]
Well so much for any hope of getting a response from MikhailV.

Well done Thundros! Another interesting thread killed! Keep this up and soon these forums will be cleansed of any of that pesky "stuff worth reading" we all hate.

Do you even know what a function pointer is? You don't, do you. For the love of all that is good in the world (what little you've left behind you) please just shut the hell up, and please, please, please never post in this thread again. Especially not to respond to this message.


On topic... Function pointers. I believe Bobysait was asking for the source to FastPointer.dll? I too would be interested in seeing this if it's ever released. It's not really a big deal, but it would be nice to make some libs able to stand alone.


Guy Fawkes(Posted 2012) [#46]
u obviously DONT "thinks" because Im not a girl, jerk -.-


Guy Fawkes(Posted 2012) [#47]
o ill respond to this message all i want. ur insignificance does NOT bother me anymore. :)


stayne(Posted 2012) [#48]
ur insignificance does NOT bother me anymore.


Perfunctory banter. Too much sugar?


Ginger Tea(Posted 2012) [#49]
I'm glad this forum doesn't rank people by post count's, these threads always end up nothing but postcount++ with little actually said.

Yes I am aware that this post is an example of what I'm talking about ;)


Yasha(Posted 2012) [#50]
does NOT bother me anymore.


I don't understand what part of any of this makes you think we give a damn about what bothers you. Your opinion doesn't matter.

You are being an irritating prick by making it impossible to keep any thread on topic with your ridiculous random insults hurled at people who made the mistake of not realising you would show up at some point in the future. You bother us.


Guy Fawkes(Posted 2012) [#51]
Mods. Please Ban him. I'm sick of him calling me names, and putting me down.

Last edited 2012


ando(Posted 2012) [#52]
.....

Last edited 2012


Guy Fawkes(Posted 2012) [#53]
U know what? thats a good idea. Since ur the creator of the idea, I will let u create it. :)


ando(Posted 2012) [#54]
.....

Last edited 2012


Bobysait(Posted 2012) [#55]
@All :
Explaining Thundros how he is wrong or not in his behavior will never make him stop ... so let us be more mature.
Let's stop contributing to this childishness, we're here to learn, we're here to share programming skill to those who need
We're for sure not here to insult people or try to explain others they are "jerk" or else as we're not here to explain a child that what he does is stupid or not (his parents should do it, or moderators, but we should just ignore him, not answer him again and again).

So, please all, Stop all this counter-productive speeches and let's go back to the real aim of this topic !

We're (for most) adult people, and for this reason, we should not take care when someone come and tell us we're "jerk", we don't mind actually because we know this is wrong, as we know that all the personns with credibility on this forum won't take care of this too
We only lose our credibility when we give this more importance than we should.

So let's get back to the topic and leave thundros tell what he wants
Just ignore him and he'll probably stop by himself, or moderators will moderate him.


sting(Posted 2012) [#56]
So has anyone gathered any stats on this pointer setup? On its overhead I mean? If not I can probably try some things myself. Just curious if this effects speed at all.


Yasha(Posted 2012) [#57]
Just curious if this effects speed at all.


Well bear in mind that to call a function by pointer, you have to first call CallFunction...

I wouldn't worry about it. In a language like C or BlitzMax you might get a difference, because function pointers change how the CPU loads the jump target and can interfere with branch prediction and so on... but Blitz3D is almost completely non-optimised anyway so this stuff is unlikely to be noticeable.

More importantly, in any situation where using function pointers is a sensible design choice (e.g. storing a bunch of "actions" in an array, with a large number of "actions"), finding a way to do it without function pointers almost always will be a lot slower (so the true comparison is not just direct call vs. pointer call; it's direct-call-at-the-end-of-a-massive-select-block vs. array-read-plus-pointer-call, or something like that).


sting(Posted 2012) [#58]
Yes, replacing a large number of "actions" is a good thing in my opinion. I've just been working around it in blitz for so long that I need to research proper optimization patterns again. :P I might play around with this.


Guy Fawkes(Posted 2012) [#59]
Bob, take ur attitude, and make like Elvis, and leave the building until u quit flaming ppl. -.- I will only stop when u stop.

I haven't done anything wrong. I am following protocol. Ur the ones who are treating me bad.

Last edited 2012


Ginger Tea(Posted 2012) [#60]
and make like Elvis,

Dying on the toilet with a burger in hand?
and leave the building

Make shift coffin just steal the other stalls door.

Last edited 2012


Bobysait(Posted 2012) [#61]
All I can say is that c++ language run faster than blitz3d does
So, to get extra stuff to do things like map, list etc ... a simple dll+decls works like a charm, but if we want to use for exemple a fast and robust physic engine (like bullet) that performs transformation on blitz entity matrix inside the dll, it could be more efficient with the function MoveEntity/TurnEntity/etc directly in the dll core
And at last, in blitz code we would only have some basic function to setup and update entities like "AddEntity" "UpdatePhysic" (with no extra function in blitz code or include of big file that we would need to export for each project)
(And it would be an better security to "protect" source when we sell libraries than releasing an include bb file)


By the way, my goal is to get all the stuff exported in a "super" dll that performs all I have ever wanted blitz3d to do, and that, without having to multiply the export "bb" includes and dll files (whole sources into a single Dll + decls and no includes)

And as I need to build mesh from splines directly in the Dll, I need pointers to CreateMesh/CreateSurface/AddVertex/AddTriangle/VertexNormal and VertexColor/VertexCoords/etc and RotateEntity/PositionEntity/ScaleEntity/...

But for sure, for scripting engine, it will never be as fast and simple as a c++ one that uses function pointers.

So, if Mark Sibly doesn't want for some reason release a new blitz3d version that allow the use of function pointers (maybe it's not possible or not in his todo list), then it would be great to have at least the fastpointer.dll source code (if MikhailV is Ok)

@Yasha : Do you think you could code something similar ? ("Yes we Can !")
I'm not a begginer for sure, but I still don't understand how to get blitz function pointers

I can only call functions using fastpointer pointers using my dll ... and with strange errors on some functions like AddTriangle that don't allow me to use variable to set V0,V1,V2 ...

for exemple, I have coded a simple "triangle" mesh in my dll using fastpointer to send pointers of blitz functions to the dll

BBAEXPint CreateSampleMesh()
{
	int mesh = bb_CreateMesh(0);
	int surf = bb_CreateSurface(mesh,0);
	bb_AddVertex (surf, -1.0f,+1.0f,0.0f, 0.0f,0.0f,0.0f);
	bb_AddVertex (surf, +1.0f,+1.0f,0.0f, 1.0f,0.0f,0.0f);
	bb_AddVertex (surf, +0.0f,-1.0f,0.0f, 0.5f,1.0f,0.0f);
	bb_AddTriangle (surf,0,1,2);
	return mesh;
};

This code works and creates a triangle that I can use in blitz3d, move, transform, access vertices etc with no issue ...


but, this
BBAEXPint CreateSampleMesh()
{
	int mesh = bb_CreateMesh(0);
	int surf = bb_CreateSurface(mesh,0);
	int a = bb_AddVertex (surf, -1.0f,+1.0f,0.0f, 0.0f,0.0f,0.0f);
	int b = bb_AddVertex (surf, +1.0f,+1.0f,0.0f, 1.0f,0.0f,0.0f);
	int c = bb_AddVertex (surf, +0.0f,-1.0f,0.0f, 0.5f,1.0f,0.0f);
	int t = bb_AddTriangle (surf,a,b,c);
	return mesh;
};

does not work.
When I run accross the vertices and triangles in blitz, the vertices are well defined but the triangle exported refers to vertices {0,0,2} (not 0,1,2) and I can't point the reason



ps : here are the source of the dll part for blitz function (I can't assume this is a good way to code it, I'm not a "real" c++ professional programmer)

the header file



the cpp file



and the blitz file that export and register pointers






pps : If needed, I made an automatic bb code to exports those 3 files that maybe will help... (it only requires a dll of my own to use List/map and a basic tokenizer)





@Thundros :
As long as you're off-topic, I don't care about what you 're saying.

Last edited 2012


Yasha(Posted 2012) [#62]
strange errors on some functions like AddTriangle


Yeah, I've noticed this as well. The Blitz3D engine functions either don't work or don't work reliably with FastPointer. The simplest option is to wrap them in a B3D user function that conforms to the FastPointer expectation (i.e. returns an int, takes one parameter, defined in Blitz code). It's not efficient but at least you get around the part where they don't work at all.


@Yasha : Do you think you could code something similar ? ("Yes we Can !")
I'm not a begginer for sure, but I still don't understand how to get blitz function pointers


Write a DLL like FastPointer, or update B3D to use function pointers?

I'd much rather write a B3D compiler that had proper native support for function pointers, actually - much easier (not least beause I'm not too sharp with the asm). If I recall correctly, Mark gave the green light to Xaron's BitsBasic project (for which I offered the start of a compiler), so it might be OK? I haven't asked. I can write a backend for my B3D-compatible example if people think there's a demand for a new compiler (it would need a 3D engine: Irrlicht wrapped with a B3D command set might be a good choice).

Last edited 2012


Bobysait(Posted 2012) [#63]
Write a DLL like FastPointer, or update B3D to use function pointers?

I thought about a Dll like FastPointer

At the moment, the way to use FastPointer with more arguments goes by passing banks or handles of type ... it's slow and not efficient
And blitz3d still remains a slow language (2 to 10% slower than c++ for most operations) it would be very intersting to have the "hard" parts coded in c++ and the body of the project coded in blitz, but as you pointed it : "if people think there's a demand for [...]"
I don't think there is much people anymore standing for blitz3d
Some of them maybe wait for a new blitz3d (V2) with next gen features, but it will never come... so ...
perhaps we should evolve to blitzmax and give credits to new 3D engines ...
I must admite I'm a bit tired to all those restrictions with blitz3d
I love this language but probably not enough to support it more longer without real new enhancements.

IMHO we're in 2012 ... maybe blitz3d should be released as open source ...

And, if 2012 was the EOH (End Of Humanity), we could know it intimately before dying :p

Last edited 2012

Last edited 2012