gpt4 book ai didi

c - 指针转换期间运行时的 EXC_BAD_ACESS

转载 作者:太空宇宙 更新时间:2023-11-04 07:36:29 24 4
gpt4 key购买 nike

我试图在这里找到错误,调试器在以下位置停止:

Pthread_create renderer passed

Renderer loop (re)started

Process 84779 stopped

* thread #4: tid = 0x3603, 0x0000000101546c4b libjess.so`render_deformation + 667 at renderer.c:472, stop reason = EXC_BAD_ACCESS (code=1, address=0x36f0000)

frame #0: 0x0000000101546c4b libjess.so`render_deformation + 667 at renderer.c:472

469 for (i = 0; i < resy*resx; i++)

470 {

471 aux = (unsigned char *) ((*(tab1) << 2 ) + (unsigned int) buffer);

-> 472 *pix = *(aux) ;

473 pix++;

474 *pix = *(aux + 1);
475 pix++;

我怀疑与指针转换有关。谁能告诉我转换它的最佳方式。

函数的完整代码(按要求):

void render_deformation(int defmode)
{
unsigned int bmax, *tab1, *tab2, *tab3, *tab4, i;
unsigned char *pix = pixel , *buf = buffer, *aux;


SDL_LockSurface(screen);

/**************** BUFFER DEFORMATION ****************/



if (video == 8)
{
buf = buffer;
tab1 = table1;
tab2 = table2;
tab3 = table3;
tab4 = table4;
bmax = resx * resy + (unsigned int) pixel;

switch(defmode)
{
case 0:
memcpy(pixel,buffer,resx * resy);
break;
case 1:
for (pix = pixel; pix < (unsigned char *) bmax ; pix++)
*pix = *(buffer + *(tab1++)) ;
break;
case 2:
for (pix = pixel; pix < (unsigned char *) bmax; pix++)
*pix = *(buffer + *(tab2++)) ;
break;
case 3:
for (pix = pixel; pix < (unsigned char *) bmax; pix++)
*pix = *(buffer + *(tab3++)) ;
break;
case 4:
for (pix = pixel; pix < (unsigned char *) bmax; pix++)
*pix = *(buffer + *(tab4++)) ;
break;
default:
printf("Problem with blur_mode\n");
}
}
else
{
pix = pixel;

bmax = resx * resy;
switch(defmode)
{
case 0:
memcpy(pixel, buffer, pitch * resy);
goto nodef;
break;
case 1:
tab1 = table1;
break;
case 2:
tab1 = table2;
break;
case 3:
tab1 = table3;
break;
case 4:
tab1 = table4;
break;

default:
printf("Problem with blur_mode\n");
}
for (i = 0; i < resy*resx; i++)
{
aux = (unsigned char *) ((*(tab1) << 2 ) + (unsigned int) buffer);
*pix = *(aux) ;
pix++;
*pix = *(aux + 1);
pix++;
*pix = *(aux + 2);
pix+=2;
tab1++;
}
nodef:;

}


SDL_UnlockSurface(screen);
}

最佳答案

aux = (unsigned char ) (((tab1) << 2 ) + (unsigned int) buffer);

我猜应该是:

aux = (unsigned char *) (((tab1) << 2 ) + (unsigned int) buffer);

255 是指针的一个非常小的值或范围...

但是需要更多的代码,至少是整个函数加上相关的定义/声明(什么是“buffer”?为什么要强制转换为 unsigned int?)。

更新 111206:

类似的事情似乎是

bmax = resx * resy + (unsigned int) pixel;

应该是:

bmax = resx * resy + (unsigned int*) pixel;

和:

aux  =  (unsigned char *) ((*(tab1) << 2 ) + (unsigned int) buffer);

应该是什么

aux  =  (unsigned char) ((*(tab1) << 2 ) + (unsigned int*) buffer);

或:

aux  =  (unsigned char*) ((*(tab1) << 2 ) + (unsigned int) buffer);

这是所有基本的指针算法:它是 pointer := pointer + scalar;pointer = scalar + pointer; ,但是 pointer := pointer + pointer; 没有意义。第一个变体是最有可能的(否则就不需要强制转换了)。

不确定类型大小,但它们至少应该是指针。

还有一些打字错误:

for (pix = pixel; pix < (unsigned char *) bmax ; pix++) {...}

pixel和pix是char*; bmax 是一个无符号整数; Actor 很臭。我希望是这样的:

for (pix = pixel; pix < pixel+bmax ; pix++) {...}

,并且可能限制 (bmax) 甚至应该乘以 4,以便为每个单元格颜色空间的 24+8 位腾出位置。

关于c - 指针转换期间运行时的 EXC_BAD_ACESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8392568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com