Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (TipmyPip, AndrewAMD, NewbieZorro), 16,660 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Debugging C++ DLL #295297
10/24/09 08:29
10/24/09 08:29
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline OP
Serious User
VeT  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
I think this question is primary for Jcl, but maybe somebofy else would be able to help.

Situation:
First part:

1) I have sources of Joint.dll library, written in VS, using C++
2) In VS project's "General" menu, "Output directory" is directory with Lite-c project
3) In VS project's "Debugging" menu, Command is "D:\GS\acknex.exe" and "Command arguments" is "D:\GSwork\NewtonWrapper\WrapperLitec\main.c"

So, if i run project in Studio: DLL compiles, Lite-c lanuches, and if i have breakpoints in DLL's code, project stops as it reaches breakpoint.

Second part:

4) Lite-c calls function from DLL:
Code:
JOINTLIBRARY_API NewtonUserJoint *CreateCustomPlayerController (const dFloat* pins, const NewtonBody* playerbody, dFloat maxStairStepFactor, dFloat cushion);
***
API (CreateCustomPlayerController, jointlibrary)
***

dFloat* globalFrame[16] = {0,1,0,0,   1,0,0,0,   0,0,-1,0,    0,0,0,1};
***
NewtonUserJoint* CharJoint = CreateCustomPlayerController (globalFrame, rigidBody, maxStairStepFactor, kinematicCushion);


5) In VS this function lookings like
Code:
NewtonUserJoint *CreateCustomPlayerController (const dFloat* localFrame, const NewtonBody* player, dFloat maxStairStepFactor, dFloat cushion)
{
	/* 1 */ return (NewtonUserJoint *) new CustomPlayerController (*(dMatrix*) localFrame, player, maxStairStepFactor, cushion);
}

CustomPlayerController::CustomPlayerController(
	const dMatrix& playerFrameInGlobalSpace,
	const NewtonBody* child, 
	dFloat maxStairStepFactor,
	dFloat cushion)
	:NewtonCustomJoint(6, child, NULL)
{
****
	/* 2 */ NewtonBodyGetMatrix (child, &matrix[0][0]);
****
}



Launching:

If i would comment CreateCustomPlayerController() call in Lice-c, everything would work fine (well, Player Controller wouldnt work, but there would be no crashes).

FIRST QUESTION
How can i know in Lite-c that DLL is loaded?
If i place breakpoints in DLL's source, complier stops there only when i launch project ONLY FIRST time. Looking like that 2nd and 3rd times, Lite-c uses another DLL as it ignores breakpoints while compiling.

How i sovled this problem: i added
wait(-1);
in Lite-c before first function calling. This gives time to load DLL (well, i think so) and now VS stops every time when compiler reaches breakpoint.

This works for now, but i would be glad to have in Lite-c some function like
bool DllIsLoaded(name_of_dll);
so i would be able to know, if DLL is loaded for current user (i'm afraid, for some users time of loading DLL could be very differ, so this would make my project unstable)

Continue launching:

Now, i uncommented function CreateCustomPlayerController() in Lite-c... and got engine crash error. So, i place first breakpoint on the string number /* 1 */ and second breakpoint on the string /* 2 */ in C++ code.

Well, looking like everything allright: engine stops at the /* 1 */ and i started to learn code. At the line /* 2 */ i noted that &matrix[0][0] holds wrong meanings of cells. Ah, i had used wrong pointers in Lite-c.

Now read carefully, please

I change Lite-c code from
Code:
dFloat* globalFrame[16] = {0,1,0,0,   1,0,0,0,   0,0,-1,0,    0,0,0,1};


to
Code:
dFloat globalFrame[16] = {0,1,0,0,   1,0,0,0,   0,0,-1,0,    0,0,0,1};


, then launch project(still with breakpoints in VS), go through breakpoints and EVERYTHING WORKS FINE(!!!).
I feel myself very happy, i remove breakpoints, launch project again and GOT A CRASH. What a ... Now i add breakpoints again, launch project and GOT A CRAHS again WITHOUT stopping at the breakpoints.

If i would change back from
Code:
dFloat globalFrame[16] = {0,1,0,0,   1,0,0,0,   0,0,-1,0,    0,0,0,1};


to
Code:
dFloat* globalFrame[16] = {0,1,0,0,   1,0,0,0,   0,0,-1,0,    0,0,0,1};


, then run, got a crash, then change again, then run again, this would work for one time.

I'm totally lost.

SECOND QUESTION, very simple
WHAT'S GOING ON???

I want to say sorry for a large number of letters, but i tried to describe problem in a clear way. Also, i'm sorry for BIG LETTERS in some cases, but they are imporatnt, as i think.
I think, i could make a video of this, if i'm not clear.


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: Debugging C++ DLL [Re: VeT] #295429
10/25/09 08:22
10/25/09 08:22
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline OP
Serious User
VeT  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Looking like i solved this with adding

Code:
wait(5);
NewtonUserJoint* CharJoint = CreateCustomPlayerController (globalFrame, rigidBody, maxStairStepFactor, kinematicCushion);



Well, so now the question is more simple: how can i know that DLL is loaded, without wait(-1); and wait(5); ?


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: Debugging C++ DLL [Re: VeT] #295432
10/25/09 09:17
10/25/09 09:17
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
ermm, maybe the WINAPI function GetModuleHandle could help? It retrieves a handle to the loaded module so check if GetModuleHandle("my.dll") returns a handle, if it does > it's loaded. If it returns NULL then its not loaded.

At least that is my understanding of the function, i've never had to use it.

You could check in a while loop...
Code:
while(1)
{
if(GetModuleHandle("my.dll") != NULL){break;}
wait(1);
}
// continue once dll is loaded



Is lite-c loading the DLL automatically? Otherwise you could use the LoadLibrary function and that returns a valid handle if the DLL is successfully loaded.

Last edited by DJBMASTER; 10/25/09 09:20.
Re: Debugging C++ DLL [Re: DJBMASTER] #295573
10/26/09 07:58
10/26/09 07:58
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline OP
Serious User
VeT  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Thanks for good idea.

But this dont work... i added
Code:
while (GetModuleHandle("Newton.dll") == NULL){wait(1);}
while (GetModuleHandle("JointLibrary.dll") == NULL){wait(1);}


and removed all wait(); function calls, but engine crashes as if there is no waiting for loading DLL at all frown


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: Debugging C++ DLL [Re: VeT] #295646
10/26/09 17:17
10/26/09 17:17
Joined: Aug 2008
Posts: 133
Sweden, Stockholm
E
Enduriel Offline
Member
Enduriel  Offline
Member
E

Joined: Aug 2008
Posts: 133
Sweden, Stockholm

you dont' need a wait, just let it keep looping, break; out of the loop when GetModuleHandle returns true.

Re: Debugging C++ DLL [Re: Enduriel] #295880
10/28/09 10:19
10/28/09 10:19
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline OP
Serious User
VeT  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Em... i dont see the difference between
Code:
while(1)
{
if(GetModuleHandle("my.dll") != NULL){break;}
wait(1);
}


and
Code:
while (GetModuleHandle("Newton.dll") == NULL){wait(1);}



Anyway, both methods dont work. frown


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: Debugging C++ DLL [Re: VeT] #295881
10/28/09 10:29
10/28/09 10:29
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
havn't read the first post, but what enduriel wanted to express is:

while(1)
{
if(GetModuleHandle("Newton.dll")) { break; }
}

or:

while(!GetModuleHandle("Newton.dll"))
;

greetings

Re: Debugging C++ DLL [Re: TechMuc] #295892
10/28/09 13:06
10/28/09 13:06
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline OP
Serious User
VeT  Offline OP
Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
Hi, TechMuc
I mean that neither
Code:
while(1)
{
if(GetModuleHandle("Newton.dll")) { break; }
}

while(1)
{
if(GetModuleHandle("JointLibrary.dll")) { break; }
}


nor
Code:
while(!GetModuleHandle("Newton.dll"));
while(!GetModuleHandle("JointLibrary.dll"));


dont work as it expected frown


If i change
Code:
action CharacterController()
{
wait(3);
***
NewtonBody* rigidBody = NewtonCreateBody (nworld, collision); 
***
}


with
Code:
action CharacterController()
{
while(!GetModuleHandle("Newton.dll"));
while(!GetModuleHandle("JointLibrary.dll"));
***
NewtonBody* rigidBody = NewtonCreateBody (nworld, collision); 
***
}


i get a crash...


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro

Moderated by  TWO 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1