Thread 1 : EXC_BAD_ACCESS in Xcode with C code - ios

I am using Xcode to code in C language. I am getting strange error.
If ranges(height2, width2) of for loops are around 500,600 code is working fine. BUT if I change ranges more than 800 then it gives me following error.
"Thread 1: EXE_BAD_ACCESS(CODE - 2, address = 07x33434...)"
for (int i = 0 ; i <height2 ; i++)
{
for (int j = 0 ; j< width2 ; j++)
{
float height_Frac_Idx = i*scale_h;
float width_Frac_Idx = j*scale_w;
int height_idx, width_idx;
height_idx = (int) height_Frac_Idx;
width_idx = (int) width_Frac_Idx;
float del_h = height_Frac_Idx - height_idx;
float del_w = width_Frac_Idx - width_idx;
img_op[i][j] = (img_IP[height_idx][width_idx])*(1 - del_h)*(1-del_w) + (img_IP[height_idx+1][width_idx])*(del_h)*(1-del_w) + (img_IP[height_idx][width_idx+1])*(1 - del_h)*(del_w) + (img_IP[height_idx+1][width_idx+1])*(del_h)*(del_w);
}
}

"Thread 1: EXE_BAD_ACCESS(CODE - 2, address = 07x33434...)"
This error come when when you accessing the unallocated or more that allocated memory in code.
Looking your code and explanation i can guess that you probably accessing some more memory in case of img_op[][] or img_IP[][] array.
Also try Enabling NSZombies
Very easy to enable:
Double click your executable in the “Executables” in XCode
Open “Arguments” tab
In “Variables to be set in the environment” (that’s the list at the
bottom, be careful which one you edit) click the “+” button and for
name of the variable enter “NSZombieEnabled” and for value “YES”

Related

DXL script producing syntax error with char c = str[i]

I'm currently trying to run Export to PDF script, however when I try running it in DOORS ver 9.6.1, I get a couple of errors.
Line 8: char c = str[i]; contains a syntax error
Any thoughts on how I can resolve this issue?
string makeCaption(Buffer& str)
{
setempty(tempBuf);
int i = 0;
{
for(i = 0; i < length(str); ++i)
char c = str[i];
if('\n' != c) && '\\' != c)
{
tempBuf += c;
}
}
escapeSpecialLaTeXCharacters(tempBuf);
return stringOf(tempBuf);
}
Seems to me like copy/paste problems. When you compare your code with the original you might notice that you moved line 6 with the sole { one line up. If you put it back where it belongs i.e. after the line "for(...)", the code works

Understanding StereoMatching in Point Cloud Library

Situation: I am trying to get point cloud with pcl::AdaptiveCostSOStereoMatching, which uses two rectified images (pics are ok).
I used these tutorials to learn how to do this:
First tutorial
Second tutorial
Error: programm crashes in runtime when calling "compute" method of AdaptiveCostSOStereoMatching
Question: how to correctly pass images to "compute" method?
I tried:
1) Images converted by png2pcd
(command line: "png2pcd.exe in.png out.pcd")
2) Images converted with function below from cv::Mat
But no luck.
Function which converts cv::Mat to pcl::PointCloud
void MatToPointCloud(Mat& mat, pcl::PointCloud<RGB>::Ptr cloud)
{
int width = mat.cols;
int height = mat.rows;
pcl::RGB val;
val.r = 0; val.g = 0; val.b = 0;
for (int i = 0; i < mat.rows; i++)
for (int j = 0; j < mat.cols; j++)
{
auto point = mat.at<Vec3b>(i, j);
//std::cout << j << " " << i << "\n";
val.b = point[0];
val.g = point[1];
val.r = point[2];
cloud->at(j, i) = val;
}
}
pcl::AdaptiveCostSOStereoMatching (compute)
// Input
Mat leftMat, rightMat;
leftMat = imread("left.png");
rightMat = imread("right.png");
int width = leftMat.cols;
int height = rightMat.rows;
pcl::RGB val;
val.r = 0; val.g = 0; val.b = 0;
pcl::PointCloud<pcl::RGB>::Ptr left_cloud(new pcl::PointCloud<pcl::RGB>(width, height, val));
pcl::PointCloud<pcl::RGB>::Ptr right_cloud(new pcl::PointCloud<pcl::RGB>(width, height, val));
MatToPointCloud(leftMat, left_cloud);
MatToPointCloud(rightMat, right_cloud);
// Calculation
pcl::AdaptiveCostSOStereoMatching stereo;
stereo.setMaxDisparity(60);
//stereo.setXOffest(0); Почему-то не распознается
stereo.setRadius(5);
stereo.setSmoothWeak(20);
stereo.setSmoothStrong(100);
stereo.setGammaC(25);
stereo.setGammaS(10);
stereo.setRatioFilter(20);
stereo.setPeakFilter(0);
stereo.setLeftRightCheck(true);
stereo.setLeftRightCheckThreshold(1);
stereo.setPreProcessing(true);
stereo.compute(*left_cloud, *right_cloud); // <-- CRASHING THERE
stereo.medianFilter(4);
pcl::PointCloud<pcl::PointXYZRGB>::Ptr out_cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
stereo.getPointCloud(318.11220, 224.334900, 368.534700, 0.8387445, out_cloud, left_cloud);
Error information:
Output log: HEAP[App.exe]:
Heap block at 0000006B0F828460 modified at 0000006B0F8284A8 past requested size of 38
App.exe has triggered a breakpoint.
left_cloud (a right cloud looks like left_cloud)
Mini question: if AdaptiveCostSOStereoMatching really allows build point cloud from 2 images, how ACSSM doing this without insintric and excentic parameters?
Problem: I downloaded and installed old version of PCL without stereo.
After that, I downloaded stereo from other PCL pack and add this library to my PCL pack. And it worked incorrectly.
Solution: I compilled PCL 1.8 and my programm is ok now.
OS: Windows
IDE: MSVS 12 2013 x64
If you will try to compile PCL, these links can help you:
Official-tutorial-1
Official-tutorial-2
Good help with FLANN and VTK
Example to verify installation

Bad Access/Pointer Issue in Objective-C

I've got the following bit of code:
Byte * tokenOut = NULL;
for (int i = 0; i < sizeof(Tknout); i++)
{
tokenOut[i * 2] = (Tknout[i] >> 8);
tokenOut[(i * 2) + 1] = (Tknout[i] & 0xFF);
}
But it generates an EXC_BAD_ACCESS error upon running when I try to update tokenOut. I'd appreciate if somebody could tell me what I'm doing wrong!
Thanks!
You are dereferencing a NULL pointer.
Try
Byte whatever;
Byte *outToken = &whatever;
// Do the rest.
Now there is valid memory for you to write to.
Except you will still have issues because you will write past the end of your variable. So maybe you wanted an array?
sizeof(outTkn) will return 1 (1 byte)

c# Format exception was unhandled

I have a method that fills up the elements of an int[,]. The elements that need to be filled are stored in a .txt file like this:
1
1
2
2
Meaning that I have to fill up the [1,1] and [2,2] element.
For this I use this but it gives the error above
int x = 0;
int y = 0;
for (int i = 0; i < 2; i++)
{
x = int.Parse(SR.ReadLine());
y = int.Parse(SR.ReadLine());
mezo.mezo[x, y] = 1;
}
Thanks in advance!
According to MSDN(http://msdn.microsoft.com/en-IN/library/b3h1hf19.aspx) a FormatException is thrown when:
s is not in the correct format.
s in your case is SR.ReadLine() which is returning some value that is not recognized as a number format.
At first look it might be because of whitespaces in your file.
Try
SR.ReadLine().Trim()
OR
NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite for the number style in the Parse method.

NSInteger cannot be used twice in same multiplication [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am stumped! I am using NSinteger but as all my inputs are integers and the results are therefore integers I can't see the problem that people doing division are having due to rounding.
I've looked in the developer guide for NSInteger and cannot find a warning.
And my searching of this site and google hasn't yielded results.
As I state at the end I can work around it, but I feel there is something simple I am missing.
All the variables are direct, no pointers yet in the first for loop, intergerOfInterest is 0, 1, 6, 7, 4, 5, 10, 11 which is very random, I have tried swapping integerValueA^2 for the calculation but with no effect. The second for loop however gives the correct answers, 6,12,20,30,2,56,72,90
for (loopCount = 0; loopCount < 8; loopCount++){
integerValueA = loopCount + 2;
integerValueB = integerValueA + 1;
intergerOfInterest = (integerValueA) * (integerValueA);
}
for (loopCount = 0; loopCount < 8; loopCount++){
integerValueA = loopCount + 2;
integerValueB = integerValueA + 1;
intergerOfInterest = (integerValueA) * (integerValueB);
}
There are several loops in the structure and the common factor between the correct number and the incorrect number is if the NSInteger is used more than once in a calculation. I figure this can't be right so does anyone have an idea how I am getting this wrong. Note: if I add an extra variable to store the second instance of the number (so in the first loop I use "(integerValueA) * (integerValueB - 1 )" it works fine.
Note: Edited to use naming conventions.
It sounds from the discussion in the comments that your original code looked something like this:
for(int i = 0; i < 8; i++) {
nVal = i ^ 2; // Supposed to be equivalent to nVal = i * i;
// Do something with nVal
}
The ^ operator in C is actually the bit-wise XOR operator, not the exponent operator. The above code takes i, flips bit 1, and assigns the result to nVal.
You want to use either of the following:
// Option 1
for(int i = 0; i < 8; i++) {
nVal = i * i;
// Do something with nVal
}
// Option 2
for(int i = 0; i < 8; i++) {
nVal = pow(i, 2);
// Do something with nVal
}
Is it possible you have a spelling error on your variable InteRgerOfInterest instead of IntEgerOfInterest ?
GH

Resources