Skip to content

halscope: fix "loadrt scope_rt failed" when reopening the scope - #4356

Merged
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:fix/halscope-relaunch
Aug 8, 2026
Merged

halscope: fix "loadrt scope_rt failed" when reopening the scope#4356
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:fix/halscope-relaunch

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

Reopening halscope fails after the first time: the window never appears again and the terminal shows loadrt scope_rt failed. From AXIS (Machine > Hal Scope) it just looks like nothing happens until LinuxCNC is restarted.

Regression from d88d10d. scope.c checks whether the realtime half is already loaded before running loadrt scope_rt, and that check was converted from a funct lookup to a component lookup:

- if (!halpr_find_funct_by_name("scope.sample")) {
+ int rv = hal_comp_by_name("scope.sample", NULL);
+ if (-ENOENT == rv) {

There is no component named scope.sample. The component is scope_rt, scope.sample is the funct it exports, so the lookup always returns -ENOENT and halscope always runs halcmd loadrt scope_rt.

Closing halscope does not unload scope_rt, it stays resident and attached to the thread. On the next launch the loadrt therefore fails and halscope calls exit(1) before creating its window.

scope_horiz.c was converted correctly in the same commit, using hal_list_funct(). This does the same in scope.c, restoring the original semantics.

Tested against a live HAL under Xvfb, closing the window with WM_DELETE_WINDOW between launches:

launch 1 launch 2 launch 3
before opens loadrt scope_rt failed, exits exits
after opens opens opens

scope.sample stays attached to the servo thread across all three, and the halscope component is removed from HAL on each close.

@grandixximo
grandixximo requested a review from BsAtHome August 8, 2026 01:53
Comment thread src/hal/utils/scope.c Outdated
@BsAtHome

BsAtHome commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

BTW, good catch.

@grandixximo

Copy link
Copy Markdown
Contributor Author

You build three times my docs, I open two times your scope...

Wouldn't it be great if the third time you try to open the scope it had yet another issue 😆

@BsAtHome

BsAtHome commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

I'd like to reach Bingo on the fourth time and an automatic payout from the machine :-)

@grandixximo
grandixximo force-pushed the fix/halscope-relaunch branch from 2c5e63c to b94f754 Compare August 8, 2026 09:55
Closing halscope leaves scope_rt loaded, so every launch after the first
has to detect that the realtime part is already there and skip the
loadrt. That detection broke in d88d10d: the funct lookup
halpr_find_funct_by_name("scope.sample") was replaced with the component
lookup hal_comp_by_name("scope.sample", NULL). No component is named
"scope.sample" (the component is "scope_rt", "scope.sample" is the funct
it exports), so the lookup always returns -ENOENT and halscope always
runs "halcmd loadrt scope_rt".

On the second launch that loadrt fails because scope_rt is already
loaded, and halscope exits immediately with "loadrt scope_rt failed".
From a GUI such as AXIS ("Machine" > "Hal Scope") the window simply
never appears again until LinuxCNC is restarted.

Look the funct up with hal_list_funct() instead, the same way
scope_horiz.c already does, which restores the original semantics.
Comment thread src/hal/utils/scope.c Outdated
@grandixximo
grandixximo force-pushed the fix/halscope-relaunch branch from b94f754 to 6c13d05 Compare August 8, 2026 10:58
@BsAtHome
BsAtHome merged commit ae2d0a7 into LinuxCNC:master Aug 8, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants