PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Access Violation Cause?

Ok, first of all, let me start off by saying I am very sorry for this. I know how annoying it is for someone to just stick a routine in front of you and say debug this. I will try to give as much help as possible, but, for now, I am really stumped as to why this is happening.

The routine
Code:
void soft_scale (UINT16 *src, int sw, int sh,
UINT16 *dst, int dw, int dh) {
int x,y,i;
float xs,ys,xx,yy;

xs = (float)dw / sw;
ys = (float)dh / sh;

if ((xs==1) & (ys==1)) {
for (y=0; y<dh; y++) {
for (x=0; x<dw; x++) *(dst++) = *(src++);
src+=1024-sw;
}
return;
}

yy = 0;
for (y=0; y<sh; y++) {
xx = 0;
yy += ys;
if (yy >= 1) {
for (x=0; x<sw; x++) {
xx += xs;
if (xx >= 1) {
for (i=0; i<(int)xx; i++) {
int j;

for (j=0; j<(int)yy; j++)
*(dst+(dw*j)) = *src;
dst++;
}
src++;
xx -= (int)xx;
}
else src++;
}
for (i=1; i<(int)yy; i++) {
dst+=dw;
}
yy -= (int)yy;
src+=1024-sw;
}
else src+=1024;
}
}

now, the values for each parameter
Code:

UINT16 *src=was char *buffer=malloc(1024*512*2)
int sw = 640
int sh = 240
UINT16 *dst = was UINT tmp[320*240], I also tried UINT * tmp = malloc(320*240) with the same problem
int dw = 320
int dh = 240


The problem occurs with this line of code
Code:

*(dst+(dw*j)) = *src;


It is at this point that the src buffer is coppied over to the dstination buffer. The violation is, to my understanding on the dst end, because when looking at the debugger, a value for *(dst+(dw*j)) is undefined where as a value for *src is defined. Also, this routine works for the first fiew loops, but after it gets to y=49 and x =41 (may occur at many spots, this is just one which I noted) it gives me an access violation.

Some background. The emu blits 16 bit code. The psx has a 1 meg video buffer that can be used for any purpose, few if any games use the entire buffer for the blit. The psx bios is 480 * 240 (resolution.

Also, I realize that the floats would slow this down, and they will be corrected later. This is the item as it appeared in the original source.

Also, I have changed the FullScreen values from 640*480 to 320*240. I do not see how this could effect the error, but anything is possible.[/b]
ignore this, I don't know why UINT tmp[w*h] was giving me an error, but when I allocated the bytes for tmp, I forgot to multiply by 2 :oops:
Code:

if ((xs==1) & (ys==1)) {


You probably don't want to be doing a bitwise AND there. Sure, it'll work, but a logical AND would be better.
which one is quicker? logical or bitwise?
Logical. An "if" statement always evaluates to a final boolean logic operation. So you have a mathemetical AND which always occurs, the result of which always has to be logically evualuated for true / false. If you use logical AND the left value is evaluated first. If it is false then it can drop out with only having performed the single test.

Also, to increase performance specify the condition most likely to be false on the left.

Dan East
That's what I was thinking, but I just wanted to make sure.