Ability to add compiler flags

UrbanCyborg
Posts: 625
Joined: Mon Nov 15, 2021 9:23 pm

Ability to add compiler flags

Post by UrbanCyborg »

I've just run up against an annoying problem after upgrading my Java to v23: some code that used to compile just fine now generates an "uninitialized variable" error, and all of my fancy comments generate "dangling-doc-comments" warnings. Lots and lots of warnings. You can't use suppress warnings in a package-info.java file, and VMD won't let you insert an -Xdoclint:none flag into compilation. Anybody got any suggestions? The error message is particularly galling, since the variable is always initialized, just in another part of the program, and there's no way to initialize it in the location where it's being used. Earlier versions of Java apparently weren't so picky.

Reid
Cyberwerks Heavy Industries -- viewforum.php?f=76
User avatar
Aarnville
Posts: 52
Joined: Sat Jun 18, 2022 5:14 pm

Re: Ability to add compiler flags

Post by Aarnville »

I'm not aware of a way to add compiler flags and I guess only the CA grown-ups know how the compiler is called from VMD. I half-expected to find an XML file with the compiler config in it but a quick browse turned up nothing.

I recently returned to the driving seat after almost two years. All the tools were newer versions but I was pleasantly surprised at how seamlessly they compiled the older modules.... except for the dangling docs thing (sounds like a disease). :o

In my case it was my somewhat bad habit of dividing up groups of functions with loads of slashes:

Code: Select all

/////////////////////////////////////////////////////
and the solution appears to be adding a space after the first two:

Code: Select all

// ///////////////////////////////////////////////////
No idea why the slashes upset JavaDoc though, because I thought it only looked for

Code: Select all

/**
As for your uninitialized var, you might have to find another way to declare/use it, although I am a bit curious as to how your var is causing that error if it is always initialised.
User avatar
utdgrant
Posts: 624
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: Ability to add compiler flags

Post by utdgrant »

UrbanCyborg wrote: Wed Nov 20, 2024 1:50 pm The error message is particularly galling, since the variable is always initialized, just in another part of the program, and there's no way to initialize it in the location where it's being used. Earlier versions of Java apparently weren't so picky.
Are you using multiple modules/classes in your project?

Is it a simple variable or an object of a user-defined class?

Is there any way to place your variable in the "User Variable & Functions" section of your main module and ensure that you supply an initial value in there?
InitVar.png
InitVar.png (136.12 KiB) Viewed 565 times
______________________
Dome Music Technologies
UrbanCyborg
Posts: 625
Joined: Mon Nov 15, 2021 9:23 pm

Re: Ability to add compiler flags

Post by UrbanCyborg »

Multiple classes and files in one project. The variables that evoke this error are all user-defined members of the main class, and I initialize them both in the Initialize() method and in a one-time-only method I run at the top of ProcessSample(). The code that causes the error is in ProcessSample(). The strange thing is that this is code I cut and pasted from an earlier project where it worked fine. The variables in question are running values for maintaining VU meters, so their values are properly set in ProcessSample(), but are set to 0.0 in Initialize() and at the top of the first run through ProcessSample() (which may be actually before the Initialize() initialization). I'm wondering if the problem has to do with the class not being totally created when the objectionable code is first run.

Reid
Cyberwerks Heavy Industries -- viewforum.php?f=76
User avatar
Aarnville
Posts: 52
Joined: Sat Jun 18, 2022 5:14 pm

Re: Ability to add compiler flags

Post by Aarnville »

ProcessSample does not start running until Initialize (and other stuff) is done so you may be able to just delete that one-time-only code in ProcessSample.
User avatar
utdgrant
Posts: 624
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: Ability to add compiler flags

Post by utdgrant »

UrbanCyborg wrote: Thu Nov 21, 2024 10:28 am The variables that evoke this error are all user-defined members of the main class, and I initialize them both in the Initialize() method and in a one-time-only method I run at the top of ProcessSample().
I'd still be tempted to perform an explicit initialization of the variable values at the point of declaration, even if it's just to an arbitrary value like 0.0. That way, you're not depending on the running order of the Initialize() method, ProcessSample(), or anything else.
______________________
Dome Music Technologies
User avatar
utdgrant
Posts: 624
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: Ability to add compiler flags

Post by utdgrant »

UrbanCyborg wrote: Thu Nov 21, 2024 10:28 am The variables in question are [...] are properly set in ProcessSample(), but are set to 0.0 in Initialize() and at the top of the first run through ProcessSample()
OK, it's difficult to debug what's happening without seeing the actual code, or at least the appropriate snippets that are causing problems. Therefore, there are a few assumptions on my part, but here goes:

Is the "first run through" section of ProcessSample() wrapped up in an "if statement", decided by examining the value of another variable (like a Boolean flag or iteration counter)?

If so, then the compiler would need to be certain that the 'first time test' variable itself is initialized to a valid value before ProcessSample() is called for the first time.

If the update to that flag/counter (to tell it NOT to run the 'first run through' code next time) happens inside that if statement, you'd still be in trouble (The compiler might not be smart enough to know that it will ALWAYS be run on the first call to ProcessSample()). Therefore, the compiler wouldn't be certain that the variable you want to initialize will ALWAYS be a assigned a value on the first call, either.

Or I could be barking up the wrong tree entirely. :lol: Again, it's hard to tell without seeing the code itself.
______________________
Dome Music Technologies
UrbanCyborg
Posts: 625
Joined: Mon Nov 15, 2021 9:23 pm

Re: Ability to add compiler flags

Post by UrbanCyborg »

Okay, here's the relevant code, trimmed down to essentials:

Code: Select all

public void Initialize()
{
    //[user-Initialize]   Add your own initialization code here
    bIsInitializing = true;                                          // still initializing
    bPresetIsLoaded = false;                                         // preset isn't done loading

    inputMeterValueL  = 0.0;
    inputMeterValueR  = 0.0;
    inputMeterLastL   = 0.0;
    inputMeterLastR   = 0.0;
    outputMeterValueL = 0.0;
    outputMeterValueR = 0.0;
    outputMeterLastL  = 0.0;
    outputMeterLastR  = 0.0;

    StartGuiUpdateTimer();

    //[/user-Initialize]
}

public boolean Notify( VoltageComponent component, ModuleNotifications notification, double doubleValue, long longValue, int x, int y, Object object )
{
    //[user-Notify]   Add your own notification handling code between this line and the notify-close comment
    switch( notification )
    {

        case GUI_Update_Timer:   // Called every 50ms (by default) if turned on
        {
            double newDrawValue = inputMeterValueL;                 // Input Meter Update Left
            inputMeterValueL    = 0.0;
            if(newDrawValue != inputMeterLastL) {
                inLevelMeterL.SetValue(newDrawValue);
                inputMeterLastL = newDrawValue;
            }
            newDrawValue     = inputMeterValueR;                    // Input Meter Update Right
            inputMeterValueR = 0.0;
            if(newDrawValue != inputMeterLastR) {
                inLevelMeterR.SetValue(newDrawValue);
                inputMeterLastR = newDrawValue;
            }
            newDrawValue      = outputMeterValueL;                  // Output Meter Update Left
            outputMeterValueL = 0.0;
            if(newDrawValue != outputMeterLastL) {
                outLevelMeterL.SetValue(newDrawValue);
                outputMeterLastL = newDrawValue;
            }
            newDrawValue      = outputMeterValueR;                  // Output Meter Update Right
            outputMeterValueR = 0.0;
            if(newDrawValue != outputMeterLastR) {
                outLevelMeterR.SetValue(newDrawValue);
                outputMeterLastR = newDrawValue;
            }
        }
        break;
    return false;
    //[/user-Notify]
}

public void ProcessSample()
{
    //[user-ProcessSample]   Add your own process-sampling code here
    if(bIsInitializing) {
        bIsInitializing = false;
        OneTimePostInit();
    }
    inputMeterValueL = Utility.Clamp(Math.max(inputMeterValueL, Math.abs(inValueL)), -1.0, 1.0);  // this generates the error for inputMeterValueL
    //[/user-ProcessSample]
}

private double         inputMeterValueL;                            // new value for input meter
private double         outputMeterValueL;                           // new value for output meter
private double         inputMeterLastL;                             // last value for input meter
private double         outputMeterLastL;                            // last value for output meter

private double         inputMeterValueR;                            // new value for input meter
private double         outputMeterValueR;                           // new value for output meter
private double         inputMeterLastR;                             // last value for input meter
private double         outputMeterLastR;                            // last value for output meter

private void OneTimePostInit() {
    inputMeterValueL  = 0.0;
    inputMeterValueR  = 0.0;
    inputMeterLastL   = 0.0;
    inputMeterLastR   = 0.0;
    outputMeterValueL = 0.0;
    outputMeterValueR = 0.0;
    outputMeterLastL  = 0.0;
    outputMeterLastR  = 0.0;
}   // OneTimePostInit()
I'm not sure whether that's going to tell you anything more, though. Thanks for the replies, anyway.

Reid
Cyberwerks Heavy Industries -- viewforum.php?f=76
User avatar
utdgrant
Posts: 624
Joined: Wed Apr 07, 2021 8:58 am
Location: Scotland
Contact:

Re: Ability to add compiler flags

Post by utdgrant »

UrbanCyborg wrote: Thu Nov 21, 2024 2:58 pm Okay, here's the relevant code, trimmed down to essentials:

Code: Select all

private double         inputMeterValueL;                            // new value for input meter
private double         outputMeterValueL;                           // new value for output meter
private double         inputMeterLastL;                             // last value for input meter
private double         outputMeterLastL;                            // last value for output meter

private double         inputMeterValueR;                            // new value for input meter
private double         outputMeterValueR;                           // new value for output meter
private double         inputMeterLastR;                             // last value for input meter
private double         outputMeterLastR;                            // last value for output meter

I'm not sure whether that's going to tell you anything more, though. Thanks for the replies, anyway.
Hi Reid,

I think a lot of your woes would be solved by simply assigning the value 0.0 to these variables at the point of declaration:

Code: Select all

private double         inputMeterValueL = 0.0;                            // new value for input meter
private double         outputMeterValueL = 0.0;                           // new value for output meter
private double         inputMeterLastL = 0.0;                             // last value for input meter
private double         outputMeterLastL = 0.0;                            // last value for output meter

private double         inputMeterValueR = 0.0;                            // new value for input meter
private double         outputMeterValueR = 0.0;                           // new value for output meter
private double         inputMeterLastR = 0.0;                             // last value for input meter
private double         outputMeterLastR = 0.0;                            // last value for output meter
You'd also be able to remove these lines from the Initialize() method, and ditch the OneTimePostInit() method completely.
______________________
Dome Music Technologies
User avatar
ChR_is
Posts: 116
Joined: Wed Sep 22, 2021 5:48 pm

Re: Ability to add compiler flags

Post by ChR_is »

UrbanCyborg wrote: Thu Nov 21, 2024 2:58 pm Okay, here's the relevant code, trimmed down to essentials:

Code: Select all

public void Initialize()
{
    //[user-Initialize]   Add your own initialization code here
    bIsInitializing = true;                                          // still initializing
    bPresetIsLoaded = false;                                         // preset isn't done loading

    inputMeterValueL  = 0.0;
    inputMeterValueR  = 0.0;
    inputMeterLastL   = 0.0;
    inputMeterLastR   = 0.0;
    outputMeterValueL = 0.0;
    outputMeterValueR = 0.0;
    outputMeterLastL  = 0.0;
    outputMeterLastR  = 0.0;

    StartGuiUpdateTimer();

    //[/user-Initialize]
}

...

private double         inputMeterValueL;                            // new value for input meter
private double         outputMeterValueL;                           // new value for output meter
private double         inputMeterLastL;                             // last value for input meter
private double         outputMeterLastL;                            // last value for output meter

private double         inputMeterValueR;                            // new value for input meter
private double         outputMeterValueR;                           // new value for output meter
private double         inputMeterLastR;                             // last value for input meter
private double         outputMeterLastR;                            // last value for output meter

...
I'm not sure whether that's going to tell you anything more, though. Thanks for the replies, anyway.

Reid
your problem is that

Code: Select all

public void Initialize()
isn't the constructor but merely another member function. Since the constructor does not initialize the member variables, the compiler assumes your variable isn't set.
i'd say, while grant's suggestion isn't best practice in general, it's probably still the best solution to this issue.
Post Reply

Return to “Module Designer”