Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) Arduino Due, Debug and nullptr (Read 4655 times)
wergor
Newbies
*
Offline


Posts: 8
Joined: Oct 9th, 2016
Arduino Due, Debug and nullptr
May 31st, 2018 at 3:27pm
Print Post  
Hi,
I'm using VM to debug a project that will run on Arduino Mega 2560, Due, ESP8266 and ESP32 boards. 

somewhere deep in my project, I've got a fixed size array of pointers to objects
Code (C++)
Select All
YAAASensor *sensors_[NUM_CONDITIONS]; 


as is good practice, I'm assigning nullptrs to all of them first chance I get
Code (C++)
Select All
for (uint8_t i = 0; i < NUM_CONDITIONS; i++)
	sensors_[i] = nullptr; 


however, nullptr checks which should then evaluate to false, evaluate to true:
Code (C++)
Select All
if (sensors_[0])
	Serial.println("WTF???"); 


this issue appears only on the Due and only if the Debug configuration is chosen. it appears with and without breakpoints present. I have not yet managed to reproduce the issue with an MCVE.
Arduino IDE 1.8.5 with Arduino SAM Boards package 1.6.11
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino Due, Debug and nullptr
Reply #1 - May 31st, 2018 at 3:40pm
Print Post  
Hi,

It's unclear what you are reporting or why you think it is different in debug v's release mode.

If you are saying this line of code fails then this is unconnected to Visual Micro.

Code (C++)
Select All
if (sensors_[0]) 



If you are saying that this line of code fails to show any serial output in debug mode then we should be clear if you are debugging ascii data or nulls/binary?

Code (C++)
Select All
Serial.println("WTF???");  




Thanks
  
Back to top
WWW  
IP Logged
 
wergor
Newbies
*
Offline


Posts: 8
Joined: Oct 9th, 2016
Re: Arduino Due, Debug and nullptr
Reply #2 - May 31st, 2018 at 5:36pm
Print Post  
Hi, 

sorry for being unclear. 
The actual code is this (no breakpoints in this case, but the presence of breakpoints does not influence the result):
Code (C++)
Select All
for (uint8_t i = 0; i < NUM_CONDITIONS; i++)
{
	sensors_[i] = nullptr;
}

if (sensors_[0])
	Serial.println("this should not happen");
else
	Serial.println("this is ok"); 


when building the release configuration, the Serial output is "this is ok" (which is expected), with the debug configuration it is "this should not happen", so either the assignment to nullptr or the check seems to have failed. I don't know how the choice of configuration could have an influence on this, do you have any ideas what could cause this issue? I could not yet recreate the issue in a simple sketch, but there are no interrupts in my project (or similarly obvious reasons that I can think of) that may cause this. I know the for loop is executed as expected, because breakpoints inside the loop (if set) are hit. (also, this issue only happens when building for the Due)
« Last Edit: May 31st, 2018 at 5:37pm by wergor »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino Due, Debug and nullptr
Reply #3 - May 31st, 2018 at 6:08pm
Print Post  
Thanks for the info.

Yes it's strange because the debug just uses serial. I assume you don't have analog or digital pin viewers enabled however again it is just reading pins and printing serial.

The only other thing debug does is to use a little bit more memory. Maybe wrong but a wild guess that maybe the "if (sensors_[0])" isn't valid, it would normally expect a bool result.

So it could be related to how the tool chain works and an unexpected result might be different with more memory used.

I also have to say that I am unsure how nullptr has been initialized? If it hasn't been initialized it will contain random values from memory.

Two questions:-

1) What happens if you make a proper comparison if (sensors_[0]!=nullptr)
2) What happens when you use NULL instead of nullptr;


  
Back to top
WWW  
IP Logged
 
wergor
Newbies
*
Offline


Posts: 8
Joined: Oct 9th, 2016
Re: Arduino Due, Debug and nullptr
Reply #4 - May 31st, 2018 at 6:42pm
Print Post  
Hi, 

I'm not using the pin viewers and I don't think memory is an issue - the program runs nicely on a Mega2560 with 8kB ram, so the Due with 96kB ram should not have any issues.
nullptr is the c++ null pointer literal (https://en.cppreference.com/w/cpp/language/nullptr). sensors_ is an array of pointers, at the time the check is performed sensors_[0] should point be pointing to NULL. I also tried setting sensors_[i] = NULL (or 0), but it does not change the result. 
nothing changes when implementing the check as sensors_[0]!=nullptr, and nothing changes when using NULL instead of nullptr
« Last Edit: May 31st, 2018 at 6:43pm by wergor »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino Due, Debug and nullptr
Reply #5 - May 31st, 2018 at 6:54pm
Print Post  
Okay thanks.

Switch on vmicro>compiler>show build folder. Then build in debug and CTR+Click to goto the build folder. Email the project_name.cpp to be info[at]visualmicro.com

Then switch on vmicro>compile>verbose and build and email the output as a .txt
Then switch to release and build, then also email the output.

Thanks

« Last Edit: May 31st, 2018 at 6:55pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
wergor
Newbies
*
Offline


Posts: 8
Joined: Oct 9th, 2016
Re: Arduino Due, Debug and nullptr
Reply #6 - Jun 2nd, 2018 at 5:35pm
Print Post  
I have sent you the requested files. 
Unfortunately, I cannot create a MCVE for this issue, so I have sent the complete contents of the Debug and Release folders of my project. If you have any questions, please don't hesitate to contact me.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12071
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Arduino Due, Debug and nullptr
Reply #7 - Jun 2nd, 2018 at 6:28pm
Print Post  
Thanks for the files.

There is a visual micro update 1806.2.1 that contains a correction to the sequence that libraries are linked. Hopefully the download in the link resolved the issue for you.

If not then please let me know where you download the BMP085 library from?

Thanks
  
Back to top
WWW  
IP Logged
 
wergor
Newbies
*
Offline


Posts: 8
Joined: Oct 9th, 2016
Re: Arduino Due, Debug and nullptr
Reply #8 - Jun 4th, 2018 at 5:53pm
Print Post  
Hi,

I tried the update today, unfortunately the problem persists.
The BMP085 library is part of the I2C Device library collection ( https://github.com/jrowberg/i2cdevlib )
I'm waiting for a new Due to arrive in the mail on the off-chance it is a problem with my particular device and will give you an update as soon as I tried it, until then I'll be working on other things.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint