Skip to content

samx3-due: Fix null result from tryAllocateQueue()#351

Merged
gin66 merged 1 commit intogin66:masterfrom
pythagorasw:fix-due-tryAllocateQueue
Mar 16, 2026
Merged

samx3-due: Fix null result from tryAllocateQueue()#351
gin66 merged 1 commit intogin66:masterfrom
pythagorasw:fix-due-tryAllocateQueue

Conversation

@pythagorasw
Copy link
Contributor

When attempting to run stepperConnectToPin() on Arduino Due (SAM3X), a null result is returned.
In sam_queue.cpp: tryAllocateQueue():
The function can only return a valid result if (fas_queue[i]._step_pin == PIN_UNDEFINED) (i.e. the pin is unallocated)

Since _step_pin is initialised by default as 0 on Due, compared to PIN_UNDEFINED = 255, tryAllocateQueue() returns null

Proposed Fix: Update definition in sam_queue.h of the class StepperQueue to explicitly initialise _step_pin as PIN_UNDEFINED:

uint8_t _step_pin = PIN_UNDEFINED;

Tested as working on Arduino Due hardware using PlatformIO

@gin66
Copy link
Owner

gin66 commented Mar 16, 2026

Thanks for the PR.

Could you please check, if the issue is still present in v1.2.1 ?
The overall tryAllocateQueue()/init() has been reworked to exactly avoid this null pointer crash.

@pythagorasw
Copy link
Contributor Author

The issue is still present in v1.2.1, at least on my hardware (Genuine Arduino Due, 2x units). Upon finding the issue, I updated to the latest version v1.2.1 but encountered the same issue. Issue was present both using PlatformIO, as well as a fresh install of v1.2.1 through the Ardiuno IDE.
The program was able to continue and run a physical stepper motor when I made this change, so I thought I'd at least share my issue and hotfix, even if it's not the most robust solution here.
Does fas_queue's _step_pin get initialised before tryAllocateQueue() somewhere that I've missed?

@gin66 gin66 merged commit 2c52937 into gin66:master Mar 16, 2026
@gin66
Copy link
Owner

gin66 commented Mar 16, 2026

Thanks for checking with v1.2.1
Based on your feedback I have revisited the code and your fix is actually solving the issue in the right way. Thanks for your support.

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