You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Replit中使用Pygame出现Double free or corruption错误求助

Replit平台Pygame开发出现C/C++风格内存错误

在Replit平台使用Pygame开发Python代码时,触发了通常出现在C/C++中的double free or corruption (!prev)内存错误,但本地Atom环境中运行完全正常,推测是Replit的环境问题。

完整错误信息

double free or corruption (!prev)
SIGABRT: abort
PC=0x7f20afd05baa m=0 sigcode=18446744073709551610
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4bb800, 0xc000061cd8)
    runtime/cgocall.go:156 +0x5c fp=0xc000061cb0 sp=0xc000061c78 pc=0x40651c
main._Cfunc_pry_eval_file(0x1ca4c10, 0x1ccf930, 0x1, 0x1d130e0)
    _cgo_gotypes.go:562 +0x4c fp=0xc000061cd8 sp=0xc000061cb0 pc=0x4b944c
main.Python.EvalFile.func5(0x1d130e0, 0x8, {0xc000012230, 0x0, 0x40ced5}, 0x0)
    github.com/replit/prybar/languages/python3/main.go:92 +0x75 fp=0xc000061d28 sp=0xc000061cd8 pc=0x4ba455
main.Python.EvalFile({}, {0x7fff05d4a31d, 0x7}, {0xc000012230, 0x0, 0x0})
    github.com/replit/prybar/languages/python3/main.go:92 +0x20c fp=0xc000061de0 sp=0xc000061d28 pc=0x4ba22c
main.(*Python).EvalFile(0x5d56d0, {0x7fff05d4a31d, 0x5d56d0}, {0xc000012230, 0x0, 0xc00007f110})
    <autogenerated>:1 +0x45 fp=0xc000061e18 sp=0xc000061de0 pc=0x4bb265
github.com/replit/prybar/utils.Language.EvalFile({{0x5075d0, 0x5d56d0}, {0x7fff05d4a307, 0xc000064100}}, {0x7fff05d4a31d, 0x7}, {0xc000012230, 0x0, 0x0})
    github.com/replit/prybar/utils/language.go:86 +0xa2 fp=0xc000061e78 sp=0xc000061e18 pc=0x4b8102
github.com/replit/prybar/utils.DoCli({0x5075d0, 0x5d56d0})
    github.com/replit/prybar/utils/utils.go:67 +0x2e8 fp=0xc000061f60 sp=0xc000061e78 pc=0x4b89a8
main.main()
    github.com/replit/prybar/languages/python3/generated_launch.go:7 +0x27 fp=0xc000061f80 sp=0xc000061f60 pc=0x4b8bc7
runtime.main()
    runtime/proc.go:255 +0x227 fp=0xc000061fe0 sp=0xc000061f80 pc=0x436d67
runtime.goexit()
    runtime/asm_amd64.s:1581 +0x1 fp=0xc000061fe8 sp=0xc000061fe0 pc=0x462e41

rax    0x0
rbx    0x6
rcx    0x7f20afd05baa
rdx    0x0
rdi    0x2
rsi    0x7fff05d48c40
rbp    0x7fff05d48f80
rsp    0x7fff05d48cb8
r8     0x0
r9     0x7fff05d48c40
r10    0x8
r11    0x200246
r12    0x7fff05d48ea0
r13    0x1000
r14    0x2
r15    0x7f2086992000
rip    0x7f20afd05baa
rflags 0x200246
cs     0x33
fs     0x0
gs     0x0
repl process died unexpectedly: exit status 2

触发错误的修改及完整代码

错误是在代码第69、71、73行添加-1后触发的,完整代码如下:

import pygame, random, math
pygame.init()
WIN_SIZE = (640, 480)
win = pygame.display.set_mode(WIN_SIZE)
pygame.display.set_caption("Anti-aliasing")
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
WHITE = (255, 255, 255)
win.fill(WHITE)

class point:
  def __init__(self, x, y):
    self.x = x
    self.y = y
class lineSegment:
  def __init__(self, p1, p2):
    self.p1 = p1
    self.p2 = p2
    self.v = point(p2.x - p1.x, p2.y - p1.y)
  def hray(self, y):
    if self.v.y == 0: return None
    n = (y - self.p1.y)/self.v.y
    if not 0<=n<=1: return None
    return self.p1.x + self.v.x * n
  def vray(self, x):
    if self.v.x == 0: return None
    n = (x - self.p1.x)/self.v.x
    if not 0<=n<=1: return None
    return self.p1.y + self.v.y * n
class tri:
  def __init__(self, p1, p2, p3):
    self.p1 = p1
    self.p2 = p2
    self.p3 = p3
    self.l1 = lineSegment(p2, p3)
    self.l2 = lineSegment(p3, p1)
    self.l3 = lineSegment(p1, p2)
    left = min(p1.x, p2.x, p3.x)
    top = min(p1.y, p2.y, p3.y)
    right = max(p1.x, p2.x, p3.x)
    bottom = max(p1.y, p2.y, p3.y)
    self.bounds = pygame.Rect(left, top, right - left, bottom - top)
  def hray(self, y):
    output = []
    l1r = self.l1.hray(y)
    if l1r != None:
      output.append(l1r - self.bounds.x)
    l2r = self.l2.hray(y)
    if l2r != None:
      output.append(l2r - self.bounds.x)
    l3r = self.l3.hray(y)
    if l3r != None:
      output.append(l3r - self.bounds.x)
    
    if len(output) == 0: return None
    if len(output) == 1:
      print("fuck")
      return None
    #print([min(output), max(output)])
    return [min(output), max(output)]
    
  def draw(self):
    surf = pygame.Surface((self.bounds.width, self.bounds.height), flags = pygame.SRCALPHA)
    array = pygame.PixelArray(surf)
    for y in range(self.bounds.height):
      mHray = self.hray(y + self.bounds.y)
      if mHray != None:
        array[round(mHray[0])-1 : round(mHray[1]), y] = BLACK
        shade = math.ceil(255 * (mHray[0]%1))
        array[round(mHray[0])-1 , y] = (shade, shade, shade)
        shade = math.ceil(255 * (mHray[1]%1))
        array[round(mHray[1])-1 , y] = (shade, shade, shade)
    array.close()
    win.blit(surf, (self.bounds.x, self.bounds.y))
    pygame.draw.rect(win, GREEN, self.bounds, 1)
    pygame.draw.circle(win, RED, (self.p1.x, self.p1.y), 2)
    pygame.draw.circle(win, RED, (self.p2.x, self.p2.y), 2)
    pygame.draw.circle(win, RED, (self.p3.x, self.p3.y), 2)
p1 = point(random.randrange(0, WIN_SIZE[0]), random.randrange(0, WIN_SIZE[1]))
p2 = point(random.randrange(0, WIN_SIZE[0]), random.randrange(0, WIN_SIZE[1]))
p3 = point(random.randrange(0, WIN_SIZE[0]), random.randrange(0, WIN_SIZE[1]))
mTri = tri(p1, p2, p3)
mTri.draw()
pygame.display.update()
print("done")

内容的提问来源于stack exchange,提问作者Jacob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 21:15:44