Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminate called after throwing an instance of 'int' #531

Closed
TheMlok opened this issue Oct 4, 2019 · 5 comments
Closed

terminate called after throwing an instance of 'int' #531

TheMlok opened this issue Oct 4, 2019 · 5 comments

Comments

@TheMlok
Copy link

TheMlok commented Oct 4, 2019

Hello,

when I compile the examples on Raspberry Pi 2 model B v1.1 I usually got this error. When I debug the code, method radio.available() returns -1 instead of bool.

I have working SPI

spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

00 00 00 00 FF FF
C0 00 00 00 00 00
00 00 00 FF FF 00
00 00 00 00 00 FF
FF 00 00 00 00 00
3F 80 00 1F 80 00
FF FC

Running out of ideas.

Thanks

M.

@wmarkow
Copy link
Contributor

wmarkow commented Oct 5, 2019

According to the latest code of RF24 library, the available() method should return either 0 or 1 which is then casted to bool. Why do you see -1? WHat version of the library you use? Maybe it is related to the compiler itself? I'm not sure right now.

Maybe you will find some warning in the compiler output?
Could you debug inside of radio.available() to see why it returns -1?

@TheMlok
Copy link
Author

TheMlok commented Oct 5, 2019

I am using latest version, compiled from github, no errors or warnings during compile. I have not debugged deeply yet, lack of time :( I will do it.
According this documentation
http://tmrh20.github.io/RF24/classRF24.html#a127105eb7a3b351cfe777c1cec50627a
it is 0 or 1, I think that -1 is made by some kind of unhandled exception deeper. But I don't know why yet.

@agrim12345
Copy link

whats the solution?

@CoRfr
Copy link
Contributor

CoRfr commented Jan 26, 2020

I'm also getting this error, but it happens in RF24::begin(), on:

write_register(NRF_CONFIG, 0x0C);
write_register(00,0c)
terminate called after throwing an instance of 'int'

@CoRfr
Copy link
Contributor

CoRfr commented Jan 26, 2020

Arg I feel a bit stupid, there is a check to make sure that the process runs as root in utility/RPi/spi.cpp:

void SPI::beginTransaction(SPISettings settings)
{
    if (geteuid() != 0) {
        throw -1;
    }

throw -1 is however not the most obvious error code.

CoRfr added a commit to CoRfr/RF24 that referenced this issue Jan 26, 2020
It appears that on Raspberry Pi, the code checks
that the process is running as root.

When it's not, it throws a very cryptic error (see nRF24#531):
  terminate called after throwing an instance of 'int'

I'm not sure that making it compulsory to run as root
is justified, but at least this change improves the
error message.

After it appears as:
  terminate called after throwing an instance of 'std::runtime_error'
    what():  Process should run as root
CoRfr added a commit to CoRfr/RF24 that referenced this issue Jan 26, 2020
It appears that on Raspberry Pi, the code checks
that the process is running as root.

When it's not, it throws a very cryptic error (see nRF24#531):
  terminate called after throwing an instance of 'int'

I'm not sure that making it compulsory to run as root
is justified, but at least this change improves the
error message.

After it appears as:
  terminate called after throwing an instance of 'std::runtime_error'
    what():  Process should run as root
CoRfr added a commit to CoRfr/RF24 that referenced this issue Jan 26, 2020
It appears that on Raspberry Pi, the code checks
that the process is running as root.

When it's not, it throws a very cryptic error (see nRF24#531):
  terminate called after throwing an instance of 'int'

I'm not sure that making it compulsory to run as root
is justified, but at least this change improves the
error message.

After it appears as:
  terminate called after throwing an instance of 'std::runtime_error'
    what():  Process should run as root
Avamander pushed a commit that referenced this issue Jan 27, 2020
When RF24 wasn't ran as root, it threw a very cryptic error (see #531): `terminate called after throwing an instance of 'int'`

This commit will improve that and now it appears as: `terminate called after throwing an instance of 'std::runtime_error' what():  Process should run as root`
@TMRh20 TMRh20 closed this as completed Mar 29, 2020
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

No branches or pull requests

5 participants