Page 1 of 3 123 LastLast
Results 1 to 15 of 45

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

  1. #1

    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

  2. #2
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,900
    Try logging to file.

  3. #3
    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 by Every4thPixel; 01-04-2017 at 04:59 AM.

  4. #4
    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.
    My opinions and comments do not represent those of my employer.
    www.ernestpchan.com
    www.zazzle.com/gopuggo

  5. #5
    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 by Every4thPixel; 01-04-2017 at 08:55 AM.

  6. #6
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,300
    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


    Quote Originally Posted by Every4thPixel View Post
    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

  7. #7
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,900
    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.

  8. #8
    Quote Originally Posted by creacon View Post
    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?

  9. #9
    @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.

  10. #10
    TrueArt Support
    Join Date
    Feb 2003
    Location
    Poland
    Posts
    7,900
    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 by Sensei; 01-05-2017 at 11:34 AM.

  11. #11
    Registered User
    Join Date
    Aug 2015
    Location
    New Brunswick, Canada
    Posts
    15
    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.

  12. #12
    LightWave Engineer Jarno's Avatar
    Join Date
    Aug 2003
    Location
    New Zealand
    Posts
    598
    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---

  13. #13
    Got it running guys! Thank you all! I think I found a new hobby

  14. #14
    creacon
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    1,300
    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

    Quote Originally Posted by Jarno View Post
    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---

  15. #15
    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.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •