How do I start the debugger from a .p file?

I created a trigger node. Currently it doesn't work on LWSN for obvious reasons. So I've to come up with a work around, but to see what actually happens I need some kind of debugger like there is with LScript.
Could someone explain to me how to debug a .p plugin? How do I start the debugger? Can I start a similar one you get with LScript, or do I need to connect the Lightwave exe in visual studio or something?
This is the first thing I've every created in C++ so I'm doing really stupid stuff probably so all tips are welcome.

Thanks
 
Can you give me a hint on how to do that?

Is this a good example? http://www.falloutsoftware.com/tutorials/c/c1.htm

I hooked it up in my file but I get this error: Access violation reading location

else
{
fputs(message, file);
fclose(file); <- here it stops <-
}

Message is empty for some reason. If directly put in a string it writes it to a file, but when I add Log(message); to my script with the message being a char it doesn't work.
 
Last edited:

ernpchan

Active member
I think he means writing to a text file. Write out what happens at certain spots in your code. Then you can see where your code breaks based on when it stops writing.
 
You mean values from variables at a certain time? Because that's what I'm trying to do. For some reason when I use Log(message); in my plugin file it generates an error. (probably because it's value is null however it should contain the word Hello (char message = "Hello "). Log is the function I created in an other file. See the link for the exact code. It's probably a noob mistake ;)

edit: I added a & to the message variable. This prevents LW from crashing but now it prints: ÄÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌYí/—mrÄÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌYí/—mrÄÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌYí/ instead of hallo. This doesn't look like the memory address to me? Am I wrong? Why don't get Hallo printed in my text file?

edit
Oh now it works. I get hello with this char variable put in directly in my plugin script. Had to make it a pointer to. Next is how to convert values to char...?

edit;
figured it out!
 
Last edited:

creacon

creacon
Are you using Visual Studio?
If yes you need to tell the VStudio debugger to launch LW (modeler or layout), put some breakpoints in your code and start debugging.

It's one of the debug options.

creacon


I created a trigger node. Currently it doesn't work on LWSN for obvious reasons. So I've to come up with a work around, but to see what actually happens I need some kind of debugger like there is with LScript.
Could someone explain to me how to debug a .p plugin? How do I start the debugger? Can I start a similar one you get with LScript, or do I need to connect the Lightwave exe in visual studio or something?
This is the first thing I've every created in C++ so I'm doing really stupid stuff probably so all tips are welcome.

Thanks
 

Sensei

TrueArt Support
I am using:

.cpp:

int Reportf(
const char *title,
const char *text,
... )
{
char buffer[ 512 ];

va_list arg;
va_start( arg, text );
vsprintf( buffer, text, arg );
va_end( arg );

int length = -1;
#ifdef _WIN32
length = MessageBox( NULL, buffer, title, MB_OK );
#endif /* _WIN32 */
#ifdef _MACOS
#endif /* _MACOS */
return( length );
}

static int Log_Depth = 0;

int Debug_Logf(
const char *filename,
const char *text,
... )
{
int length = -1;
FILE *file;
file = fopen( filename, "a" );
if( file != NULL )
{
va_list arg;
va_start( arg, text );

int i;
for( i = 0; i < Log_Depth; i++ )
{
fprintf( file, " " );
}

length = vfprintf( file, text, arg );
va_end( arg );
fclose( file );
}
return( length );
}



void DEBUG_ENTER(
const char *function )
{
Debug_Logf( LOGFILENAME, "Entering %s\n", function );
Log_Depth++;
}

void DEBUG_LEAVE(
const char *function )
{
Log_Depth--;
Debug_Logf( LOGFILENAME, "Leaving %s\n", function );
}



.h:


void DEBUG_ENTER( const char * );
void DEBUG_LEAVE( const char * );

void ENTER( const char * );
void LEAVE( const char * );

#ifdef DEBUG
#define ENABLE_LOG
#endif /* DEBUG */

#ifdef DEBUG
#define ENTER( function ) DEBUG_ENTER( function )
#define LEAVE( function ) DEBUG_LEAVE( function )
#else
#define ENTER( text )
#define LEAVE( text )
#endif /* DEBUG */


f.e. if function/method is:

class Blah
{
public:
void Blah()
{
ENTER( "Blah::Blah()" );
LEAVE( "Blah::Blah()" );
}
};

After turning debugging, every enter/leave is recorded to file. And they are nested.

In each source file it could be enabled/disabled.

If somebody informs me that plugin is crashing, I am enabling debugging, sending such modified plugin, and user is running and returning log.txt,
and each enter (nested) is there,
and if there is no leave from function,
crash must occurred in that function/method.
 
Are you using Visual Studio?
If yes you need to tell the VStudio debugger to launch LW (modeler or layout), put some breakpoints in your code and start debugging.

It's one of the debug options.

creacon

Yes I'm using Visual Studio. Should I use "Attach to Process"? I can't seem to get that working. It says "Failed to connect to process 21424: Failed to compile debugging script". Could the file extension be a problem? I think it's looking for .dll and my file is renamed to a .p file? Or do I need to hook LW up somewhere in the debug setting so when I press the green play button it launches layout.exe?
 
@Sensei Your code look similar to what I have now, but more extensive of course. Thanks for sharing. This really helps to get my head around this all.
 

Sensei

TrueArt Support
There are various Visual Express versions.
In Visual Express 2008, on either WinXP, and Win7 64 bit OS, 32 bit plugin and 32 bit Modeler, I don't have problem with Attach To Process..
Plugin extension standard .p of course.
 
Last edited:

Vorlath

New member
I just finished writing a plugin not long ago and did extensive debugging on it. I just launch Modeler. Start up MSVC and load my project. Attach to process... select Modeler in the list of processes and click OK. That's it. When you activate your plugin in Lightwave, it will load it into memory and will trigger any breakpoints you have set. The .p extension does not matter.

Note that you need the debug version of the plugin. There's a way to do it in release mode, but you can't view all variables and the one that it does show aren't guaranteed to show the actual values because of optimizations.
 

Jarno

Post-LW Engineer
Go to your plugin project properties in Visual Studio. In the Debugging settings, set the Command to the executable of Layout or Modeler (or lwsn). Start debugging.
If you have any breakpoints set, they will be used when your plugin is loaded and executed.

You can also set the Command Arguments to load a test scene on startup for example.

If you are switching between debug and release builds, make sure the right one is being used by LW.

---JvdL---
 

creacon

creacon
That's what I was trying to say, but you said it better :)
I have added paths for specific debug cfg's that use the debug version of my plugins. My regular LW shortcut uses the release version.

creacon

Go to your plugin project properties in Visual Studio. In the Debugging settings, set the Command to the executable of Layout or Modeler (or lwsn). Start debugging.
If you have any breakpoints set, they will be used when your plugin is loaded and executed.

You can also set the Command Arguments to load a test scene on startup for example.

If you are switching between debug and release builds, make sure the right one is being used by LW.

---JvdL---
 
I noticed that too. I just didn't know where to put the Layout.exe file path. I'm now going to make a function that loops thru all the frame to detect when the switch happens so I can use the trigger on LWSN as well. If anyone has any tips they are more than welcome.
 
So here's an other one... I created a loop like this:

for (int i = sceneinfo->frameStart; i > sceneinfo->frameEnd; i++) {
char *mess[sizeof(i)];
sprintf(mess, "%3.3f ", i);
Log(mess);

}

When I check i it is some big negative number like -8654367 or something like that. Even when I declare i first like this int i = 0; and then use it in the loop it still gets that odd number. Can someone tell me why this isn't 0 like I want it to be? When I make it a static int and initialize it outside the loop it works but I want it all happening inside the loop.
 
Last edited:

Sensei

TrueArt Support
Are you beginner in C/C++ ?

What is this?
char *mess[sizeof(i)];

sizeof( i ) variable is 4...

Output buffer for printing floats must have at least 16 bytes long or so...

%3.3f formatting command has 3 integer digits, 1 dot, 3 float digits, and 1 eol, and 1 for null characters.
In total 3+1+3+1+1=9 bytes must be.

Why you used " i > sceneinfo->frameEnd" ?
frameEnd typically is bigger number than frameStart..

Also sprintf/printf() expects i variable to be integer,
if you want to print it as float, you need type-casting..

Replace it by:

for (int i = sceneinfo->frameStart; i <= sceneinfo->frameEnd; i++) {
char mess[16];
sprintf(mess, "%3.3f ", (float) i);
Log(mess);

}

or


for (int i = sceneinfo->frameStart; i <= sceneinfo->frameEnd; i++) {
char mess[16];
sprintf(mess, "%3.3f ", (float) i);
Log(mess);

}

or even

for (int i = sceneinfo->frameStart; i <= sceneinfo->frameEnd; i++) {
char mess[16];
sprintf(mess, "%d", i);
Log(mess);

}
 
Last edited:

creacon

creacon
Sensei, I'd move the char mess[16] before the loop. sprintf adds a null character, so you can reuse the variable.
 
Yes, I'm a total noob at C/C++. I started with c# about a year ago so I'm a programming rooky in general. I noticed the < being in the wrong direction. Stupid mistake that was.

I copied the print line from a different part of my script that worked and I got some problems with puting int's in it. So i was a bit lazy and didn't change it because it did print what I wanted to know. Now I cleaned my code a bit and I'M using %d option.

@creacon I did that ad well. Now I'm reusing the same variable multiple times.

I think the node is almost doing what it should do a the moment but it still needs a lot of testing. F10 renders already worked but now it should work on lwsn too. Fingers crossed

Thanks for the help guys. Sometimes I just need a little push.
 

Sensei

TrueArt Support
The main issue with you code is this line
"char *mess[sizeof(i)];"

Trying to print to mess, will end up writing to random memory, trashing it, and causing random (or constant) crashes.

char *memory[ size ];
is array (with quantity 'size') of pointers to strings.

char string[ size ];
is string with defined size.
 
Top Bottom