Skip to content

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

Open
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:fix/halscope-relaunch
Open

halscope: fix "loadrt scope_rt failed" when reopening the scope#4356
grandixximo wants to merge 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.

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.
@grandixximo
grandixximo requested a review from BsAtHome August 8, 2026 01:53
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.

1 participant