Skip to content

Fix "Access Violation" (#12704)#12856

Merged
RF47 merged 3 commits into
OrcaSlicer:mainfrom
RF47:Fix-Access-violation
Apr 5, 2026
Merged

Fix "Access Violation" (#12704)#12856
RF47 merged 3 commits into
OrcaSlicer:mainfrom
RF47:Fix-Access-violation

Conversation

@RF47

@RF47 RF47 commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

Description

Add early returns in process_M1020 and process_T when the parsed extruder/filament id is out of range to avoid calling process_filament_change with an invalid index.

Screenshots/Recordings/Graphs

image image

Tests

Cube.zip

Fix #12704
Related to #12684

@RF47 RF47 marked this pull request as ready for review March 20, 2026 00:30
@RF47 RF47 added the bug-fix label Mar 20, 2026
@RF47 RF47 changed the title Fix "Access Violation" Fix "Access Violation" (#12704) Mar 20, 2026
@kisslorand

Copy link
Copy Markdown
Contributor

Note: I don’t know what the root cause is of it accepting an invalid filament; I need help with that

Cube.3mf contains custom printer G-code with literal T10 commands in machine_end_gcode

Orca parses that T10, correctly recognizes it as invalid because 10 >= m_result.filaments_count, but then still calls process_filament_change(10).

if (eid >= m_result.filaments_count)
   BOOST_LOG_TRIVIAL(error) << "Invalid T command (" << command << ").";
process_filament_change(eid);

So the access violation is not caused by the 3MF being broken. It is caused by:

  • Project-specific custom G-code using T10 as a printer command.
  • Newer Orca misinterpreting that as a slicer filament change.
  • A missing early return after detecting the tool id is out of range.

Same behavior can be observed with M1020 command also:

if (eid >= m_result.filaments_count)
    BOOST_LOG_TRIVIAL(error) << "Invalid M1020 command (" << line.raw() << ").";
process_filament_change(eid);

I would fix it like this:

void GCodeProcessor::process_M1020(const GCodeReader::GCodeLine &line)
{
    ...
    else {
        if (eid >= m_result.filaments_count) {
            BOOST_LOG_TRIVIAL(error) << "Invalid M1020 command (" << line.raw() << ").";
            return;
        }
        process_filament_change(eid);
    }
}

void GCodeProcessor::process_T(const std::string_view command)
{
    ...
    else {
        if (eid >= m_result.filaments_count) {
            BOOST_LOG_TRIVIAL(error) << "Invalid T command (" << command << ").";
            return;
        }
        process_filament_change(static_cast<int>(eid));
    }
}

or

void GCodeProcessor::process_M1020(const GCodeReader::GCodeLine &line)
{
    ...
    else {
        if (eid >= m_result.filaments_count)
            BOOST_LOG_TRIVIAL(error) << "Invalid T command (" << command << ").";
        else
            process_filament_change(static_cast<int>(eid));
    }
}

void GCodeProcessor::process_T(const std::string_view command)
{
    ...
    else {
        if (eid >= m_result.filaments_count)
            BOOST_LOG_TRIVIAL(error) << "Invalid T command (" << command << ").";
        else
            process_filament_change(static_cast<int>(eid));
    }
}

@RF47

RF47 commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator Author

I'll try it as soon as I can, Thanks!

@Felix14-v2 Felix14-v2 mentioned this pull request Mar 20, 2026
1 task
@RF47

RF47 commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator Author

I'll try it as soon as I can, Thanks!

@kisslorand it works, you are right.

@Noisyfox

Copy link
Copy Markdown
Collaborator

with literal T10 commands in machine_end_gcode

Shouldn't we raise a proper error message saying something like "invalid T10 command" instead of silently ignoring it?

@RF47

RF47 commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator Author

with literal T10 commands in machine_end_gcode

Shouldn't we raise a proper error message saying something like "invalid T10 command" instead of silently ignoring it?

But in that case, an error message would pop up for every slice in that machine profile – wouldn't that be rather annoying?

something like that?
image

@Noisyfox

Noisyfox commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator

But in that case, an error message would pop up for every slice in that machine profile – wouldn't that be rather annoying?

Then maybe fix that profile? Unless a "T10" is required for that printer to function properly, otherwise it just doesn't make sence to me.

@RF47

RF47 commented Mar 27, 2026

Copy link
Copy Markdown
Collaborator Author

Then maybe fix that profile? Unless a "T10" is required for that printer to function properly, otherwise it just doesn't make sence to me.

#12704 (comment)

@Noisyfox

Copy link
Copy Markdown
Collaborator

I see. That's kinda annoying but I guess we have to live with that then.

@Felix14-v2

Felix14-v2 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

something like that?

Adding a warning notification is dangerous: one may think that the profile is broken and try to "fix" it themselves by removing unknown Gcode commands. Which may cause damage to the printer during the execution process.

If we need a warning anyways, I'd prefer it to be displayed under the gcode section when you edit printer gcode.

@RF47

RF47 commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator Author

something like that?

Adding a warning notification is dangerous: one may think that the profile is broken and try to "fix" it themselves by removing unknown Gcode commands. Which may cause damage to the printer during the execution process.

If we need a warning anyways, I'd prefer it to be displayed under the gcode section when you edit printer gcode.

In the current implementation, it saves it in the log.

@Noisyfox

Copy link
Copy Markdown
Collaborator

Yeah if it's required for that printer to work, then we should not warn the user to avoid any confusion.

@RF47 RF47 mentioned this pull request Apr 2, 2026
3 tasks
RF47 and others added 3 commits April 5, 2026 12:10
Added an assertion to validate filament ID before processing.
Add early returns in process_M1020 and process_T when the parsed extruder/filament id is out of range to avoid calling process_filament_change with an invalid index (also add braces for clarity). Remove a redundant runtime bounds check in process_filament_change, leaving the existing assert as the intended safeguard in debug builds. This prevents potential invalid access while keeping error logging for malformed commands.

Co-Authored-By: Kiss Lorand <[email protected]>
@RF47 RF47 force-pushed the Fix-Access-violation branch from 34b6d27 to 1cdb280 Compare April 5, 2026 15:10
@RF47 RF47 merged commit cfc2e9b into OrcaSlicer:main Apr 5, 2026
17 checks passed
@RF47 RF47 deleted the Fix-Access-violation branch April 5, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ACCESS_VIOLATION] in 2.3.2-dev when trying to slice using profile for 2.3.1

4 participants