【问题标题】:CGContextRestoreGState: invalid context 0x0CGContextRestoreGState:无效的上下文 0x0
【发布时间】:2012-06-26 22:42:08
【问题描述】:

我正在尝试绘制一个简单的线条系统,但是当我尝试在终端(运行 OS X Lion)或 DrPython 中运行代码时,我收到一个错误(CGContextRestoreGState:无效上下文 0x0)。我正在运行 python 2.7。

import pygame as pg
pg.init()
screen = pg.display.set_mode((640,480))
l1 = 1.0 * L
l2 = 0.5377 * L
l3 = 0.2867 * L
hip = (100,100)
knee = (hip[0] + math.sqrt(2) * l1, hip[1] + math.sqrt(2) * l1)
ankle = (knee[0] + math.sqrt(2) * l2, knee[1] + math.sqrt(2) * l2)
toe = (ankle[0] + l3, ankle[1])
pg.draw.lines(screen, (0, 0, 0), False, [hip, knee, ankle, toe], 1)
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
raise SystemExit

【问题讨论】:

    标签: python macos pygame


    【解决方案1】:

    额外问题的数量:

    • 什么是“L”?您可能已将其编辑掉。
    • 您需要在主循环中调用 pygame.display.flip(),否则您将看不到任何内容。
    • 建议您传递给 pygame.draw.lines 的元组列表是 整数的元组。你的包括浮动元组。
    • 缩进。我会假设它在您的原始来源中是正确的。

    您的主要问题是正在创建的上下文无效。我假设这是在调用 pygame.display.set_mode 时发生的。快速的 Google 搜索显示,如果发生错误,CGContextRestoreGState 会将上下文设置为 NULL。您在那里找到的答案将帮助您解决问题。

    特别是,关键问题是,在哪里(哪一行)您的错误发生在哪里? PyGame 示例是否有效?

    【讨论】:

      猜你喜欢
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      • 2013-10-30
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多