[英](C++) Getting error “Illegal instruction (core dumped)” upon bitwise OR operation
因此,我仍在学习按位运算,无法弄清楚为什么会发生此错误。 我已经用谷歌搜索了,看来当弄乱堆栈时可能会发生此错误,或者在某些情况下,它与CPU体系结构有关。 我尝试使用本来可以帮助的不同标志进行编译,但我无法使其正常工作。
这是快速的代码:
int corners = 0;
for (int i = 0; i < 8; i++)
{
const ivec3 cornerPos = leaf->min + CHILD_MIN_OFFSETS[i];
const float density = Density_Func(vec3(cornerPos));
const int material = density < 0.f ? MATERIAL_SOLID : MATERIAL_AIR;
corners |= (material << i);
}
并且错误“非法指令(核心已转储)”发生在该行
corners |= (material << i);
这是调试器的输出:
Signal received: SIGILL (Illegal instruction) For program, pid 26,118
我将给出此循环的输出(它永远不会超过第一个循环)。 这是提示的代码:
int corners = 0;
std::cout<<"corners(outside loop): "<<corners<<std::endl;
for (int i = 0; i < 8; i++)
{
const ivec3 cornerPos = leaf->min + CHILD_MIN_OFFSETS[i];
std::cout<<"cornerPos.x: "<<cornerPos.x<<std::endl;
std::cout<<"cornerPos.y: "<<cornerPos.y<<std::endl;
std::cout<<"cornerPos.z: "<<cornerPos.z<<std::endl;
const float density = Density_Func(vec3(cornerPos));
std::cout<<"density: "<<density<<std::endl;
const int material = density < 0.f ? MATERIAL_SOLID : MATERIAL_AIR;
std::cout<<"material: "<<material<<std::endl;
std::cout<<"MATERIAL_SOLID: "<<MATERIAL_SOLID<<std::endl;
std::cout<<"MATERIAL_AIR: "<<MATERIAL_AIR<<std::endl;
std::cout<<"i: "<<i<<std::endl;
corners |= (material << i);
std::cout<<"corners(inside loop): "<<corners<<std::endl;
}
这是输出:
[corners(outside loop): 0] [cornerPos.x: -32] [cornerPos.y: -32] [cornerPos.z: -32] [density: -30] [material: 1] [MATERIAL_SOLID: 1] [MATERIAL_AIR: 0] [i: 0]
有人可以为我提供原因的任何见解,如果有明确的原因,如何解决问题,我将不胜感激。
谢谢!
“非法指令”表示CPU试图执行不理解的指令。 如果您使用CPU不支持的指令集编译程序,则可能会发生这种情况。 此处的崩溃可能表明使用了BMI2移位指令(在还支持AVX2的CPU上支持该指令)。 请检查您的编译选项。
另一种可能性是您的程序已覆盖其某些代码。 它位于与堆栈不同的内存区域,因此事情真的很混乱。 我怀疑这里不是这样。
这也可能是由过热或某些CPU错误引起的,但这些原因很可能也可以在此处排除。 对于编译器中可能的错误也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.