AS2 - Trying to create a grid of boxes - actionscript

This is my current code:
_root.createEmptyMovieClip("noteGrid", _root.getNextHighestDepth());
for(i = 1; i <= 14; i++){
currentBlock = _root.noteGrid.attachMovie("block", "block" + i, _root.noteGrid.getNextHighestDepth);
currentBlock._x = Math.floor(i / 7) * 25;
currentBlock._y = (i % 7) * 25;
}
I have a movieclip with linkage set to block. When I compile this, the block appears however they are all on top of each other. When I used trace commands to find currentBlock._x, they are the correct values.

The problem lies with your setting of depths.
_root.noteGrid.getNextHighestDepth
You are trying to access a property of noteGrid, if you trace it you will see it tells you it is a function, rather than calling a function. To call the function do
_root.noteGrid.getNextHighestDepth()
By the looks of things your code isn't quite what you want but that can't really be fixed without you giving more details about what you're trying to do. Assuming you're trying to make a 2x7 grid, then you'll want to change your for loop to
for(i = 0; i < 14; i++)

Related

Compute shader hangs when setting two pixels while looping RWTexture2D (DirectX11, SM5)

I'm trying to perform some basic cellular automata on compute shader (DirectCompute) but without double buffering, so I'm using unordered access view to a RWTexture2D<uint> for the data, however I'm having some really strange hang/crash here, I could make a very small snippet that produces the issue:
int w = 256;
for (int x = 0; x < w; ++x)
{
for (int y = 1; y < w; ++y)
{
if (map[int2(x, y - 1)])
{
map[int2(x, y)] = 10;
map[int2(x, y-1)] = 30;
}
}
}
where map is RWTexture2D<uint>.
If I remove the if or one of the assignments, it works, I thought it could be some kind of limit so I tried looping just 1/4 of the texture but the problem persists. That code is dispatched with (1,1,1) and kernel numthreads is (1,1,1) too, in my real-world scenario I want to loop from bottom to top and fill the voids (0) with the pixel I'm currently looping (think of a "falling sand" kind of effect), so it can't be parallel except in columns since it depends on the bottom pixel.
I don't understand what is causing the shader to hang though, there's no error or anything, it simply hangs and never not even times out.
EDIT:
After some further investigation, I came across something really intriguing; when I pass that w value in a constant buffer it all works fine. I have no idea what would cause that, maybe it's some compiling optimization that went wrong, maybe it tries to unroll the loop what causes some issue, and passing the value in a constant buffer disables that, however I'm compiling the shaders in debug with no optimization so I don't know.
I've had issues declaring variables in global scope like this before. I believe it's because it's not static const (so declare as a static const and it should work). Most likely, it's treating it as a constant buffer (with some default naming) and the contents are undefined since you're not binding a buffer, which causes undefined results. So the following code should work:
static const int w = 256;
for (int x = 0; x < w; ++x)
{
for (int y = 1; y < w; ++y)
{
if (map[int2(x, y - 1)])
{
map[int2(x, y)] = 10;
map[int2(x, y-1)] = 30;
}
}
}

Have issue with pretty simple C code

I am developing an app in XCode and have to write a bit of C for an algorithm. Here is a part of the C code:
double dataTag[M][N];
// dataTag initialized to values.....
double w[N]; // This is outside for loop at the top level of the method
for (int i = 0; i < N; i++) {
w[i] = pow(10.0, dataTag[2][i] / 10.0 / b);
}
//This is inside for loop.....
double disErr[N];
// disErr set and values confirmed with printArray...
double transedEstSetDrv[N][M];
// transedEstSetDrv set and values confirmed with printArray...
double stepGrad[M] = {0, 0, 0};
for (int j = 0; j < M; j++) {
double dotProductResult[M];
dotProductOfArrays(w, disErr, dotProductResult, N);
stepGrad[j] = sumOfArrayMultiplication(transedEstSetDrv[j], dotProductResult, M);
}
// Print array to console to confirm values
NSLog(#"%f %f %f", stepGrad[0], stepGrad[1], stepGrad[2]); <-- if this is present algorithm gives different results.
//Continue calculations......
So this is a part of algorithm in C which is inside for loop. The weird part is the NSLog that prints stepGrad array. Depending if i comment the call to the NSLog or not - the algorithm as a whole gives different results.
It would be great if someone gave some debugging suggestions.
Thanks!
UPDATE 1:
Simplified example which has the same issue and gave more code to support the issue.
UPDATE 2:
Removed the length_of_array function and just replaced it with a known number for simplicity.
So i will answer my own question.
Thanks to the comment from #Klas Lindbäck, i fixed the issue which was related to not initializing a C static array in for loop. So i went over all arrays before and after the code that had issue and did a
memset(a_c_array, 0, sizeof(a_c_array));
after declaration of each array. That is now working fine. Thank you for all your help!

OpenCV - Can't access all pixels in a Mat

I'm trying to manually change every pixel in a Mat.
For simplicity reasons, let's say I want to color each pixel black. I'm using the following method:
for (int i = 0; i < imageToWorkWith.rows; i++) {
for (int j = 0; j < imageToWorkWith.cols; j++) {
imageToWorkWith.at<cv::Vec3b>(i,j) = cv::Vec3b(0,0,0);
}
}
Logically, it seems like this should go over every pixel in the mat, as it reads all the possible combinations of row/col.
Unfortunately, this doesn't work. For every image, I'm missing a "chunk" of columns. For example, when loading this image:
The result is this:
This "chunk" I'm missing is the same size, no matter what image I use. I can't seem to understand the reason for that. I know that the order of row/col for the "at" function is (row, col), but i tried switching them just for kicks, and the result of course is even worse.
What am I missing here? is looping over all rows/cols not enough?
Just use Vec4b instead of Vec3b as the image by default is having 4 channels in ios. The result will be full white.
for (int i = 0; i < imageToWorkWith.rows; i++) {
for (int j = 0; j < imageToWorkWith.cols; j++) {
imageToWorkWith.at<cv::Vec4b>(i,j) = cv::Vec4b(0,0,0);
}
}

Objective C++ for loop multiple initialize fails

So I traced a bug in Objective C++ for iOS to this code
for(int i = (maxBin - 4), max = 0; i <= (maxBin + 3); i++) {
max += (fftValLeft[i] * fftValLeft[i]);
}
The "max = 0;" doesn't happen. I moved the initialization before the loop and all is good now.
This is with Xcode 4.6.3. Is this somehow normal C behavior?
You are creating a new variable called max whose scope is only visible to the for loop.
So once you come out of the loop, max value that you compute inside the loop is not visible outside of it.
Hope that helps.

SIGSEGV Error occurs on the actual device but not on ios simulator

I am the developer of a cydia tweak named CountdownCenter. I was trying to create a digital clock appearance for my widget, so I created a sample app that does this perfectly. After doing this, I transferred this data into the code of my tweak but, this causes a SIGSEGV crash on my iPhone. After some testing, I found the part that is responsible for the crash, but I just can't find what's wrong as this part would work on a normal app. Can you help me please?
Here is the code:
int digitarray[10];
int c = 0;
digitarray[0] = 0;
digitarray[1] = 0;
while (secon>0) {
int digitt = secon % 10;
digitarray[c] = digitt;
secon /= 10;
c++;
}
lbl.text = [NSString stringWithFormat:#"%d", digitarray[0]];
[self selectimage:digitarray[0] img:numview10];
SIGSEGV usually means, that you're trying to access memory, that you are not allowed to access. (btw are you testing this with a release build?) Maybe f.e. here (there are some other similar places too):
c = 0;
while (secon>0) {
int digitt = secon % 10;
digitarray[c] = digitt;
secon /= 10;
c++;
}
There are some possibilities:
secon (horrible variable names btw...) is a float or double, in that case the while loop is either never entered or never left
c becomes so large that it's beyond digitarray's bounds
To solve this issue I would recommend to but a breakpoint at the beginning of your code and check it step by step.

Resources