3 registered members (NewbieZorro, TipmyPip, 1 invisible),
19,045
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Debugging C++ DLL
#295297
10/24/09 08:29
10/24/09 08:29
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
OP
Serious User
|
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:
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
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 QUESTIONHow 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, pleaseI change Lite-c code from
dFloat* globalFrame[16] = {0,1,0,0, 1,0,0,0, 0,0,-1,0, 0,0,0,1};
to
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
dFloat globalFrame[16] = {0,1,0,0, 1,0,0,0, 0,0,-1,0, 0,0,0,1};
to
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.
|
|
|
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
OP
Serious User
|
OP
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Looking like i solved this with adding
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); ?
|
|
|
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
Serious User
|
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...
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
OP
Serious User
|
OP
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Thanks for good idea. But this dont work... i added
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 
|
|
|
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
OP
Serious User
|
OP
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Em... i dont see the difference between
while(1)
{
if(GetModuleHandle("my.dll") != NULL){break;}
wait(1);
}
and
while (GetModuleHandle("Newton.dll") == NULL){wait(1);}
Anyway, both methods dont work. 
|
|
|
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
OP
Serious User
|
OP
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Hi, TechMuc I mean that neither
while(1)
{
if(GetModuleHandle("Newton.dll")) { break; }
}
while(1)
{
if(GetModuleHandle("JointLibrary.dll")) { break; }
}
nor
while(!GetModuleHandle("Newton.dll"));
while(!GetModuleHandle("JointLibrary.dll"));
dont work as it expected  If i change
action CharacterController()
{
wait(3);
***
NewtonBody* rigidBody = NewtonCreateBody (nworld, collision);
***
}
with
action CharacterController()
{
while(!GetModuleHandle("Newton.dll"));
while(!GetModuleHandle("JointLibrary.dll"));
***
NewtonBody* rigidBody = NewtonCreateBody (nworld, collision);
***
}
i get a crash...
|
|
|
|