内存错误是由Common Lisp中管理不当的C外部对象引起的。

huangapple go评论58阅读模式
英文:

Memory error caused by mismanaged C foreign objects in Common Lisp

问题

错误

在REPL中,重新打开应用程序时:

错误:接收到信号编号11(分段违规)
[条件类型:SYNCHRONOUS-OPERATING-SYSTEM-SIGNAL]

还要求我检查错误点,来自lispbuilder-sdl的DRAW-STRING-BLENDED-*

尝试启动应用程序时(启动时崩溃):

未处理的内存错误在#x2968800处。

背景

我使用lispbuilder-sdl库与SDL进行接口。该库有一个方便的宏WITH-INIT,用于处理SDL和音频等子系统的打开和关闭。

我的解决尝试

1)
我认为字体对象的内存没有被正确释放。我将字体对象存储如下:

(defvar *menu-font* (initialise-font *ttf-font-simonetta-regular-50*))

我添加了lisp代码,在关闭过程中释放了所有预定义的字体,但没有帮助。

2)
我在一个单独的线程中有一个进程,看起来像这样:

(defun playloop ()
  (setf *playthread* 
    (bt:make-thread
     ; 执行lambda时立即调用setf
     (lambda ()
       (mapcar #'(lambda (pair)
                   (clear-display *black*)
                   (draw-lyric (car pair))
                   (update-display) 
                   (sleep (cdr pair)))
         *song*))))).

作为退出过程的一部分,我销毁了该线程。退出应用程序没有问题,只有重新启动时才会出现错误。

非常感谢任何建议。

英文:

Error

In the REPL, when re-opening the app:

Error: Received signal number 11 (Segmentation violation)
[condition type: SYNCHRONOUS-OPERATING-SYSTEM-SIGNAL]

Also asks me to check point of error, DRAW-STRING-BLENDED-* from lispbuilder-sdl

When attempting to launch the app (it crashes on launch):

Unhandled memory fault at #x2968800.

Background

I use the lispbuilder-sdl library to interface with SDL. This library has a convenience macro WITH-INIT which handles the opening and closing of SDL and subsystems like audio and ttf fonts.

My attempts to resolve

1)
I figured the memory from the font objects was not being properly freed. I store the font objects like this:

(defvar *menu-font* (initialise-font *ttf-font-simonetta-regular-50*))

I added lisp code to free all my pre-defined fonts as part of the shutdown process, but it didn't help.

2)
I have a process in a separate thread which looks like this:

(defun playloop ()
  (setf *playthread* 
    (bt:make-thread
     ; executes lambda instantly upon call to setf
     (lambda ()
       (mapcar #'(lambda (pair)
                   (clear-display *black*)
                   (draw-lyric (car pair))
                   (update-display) 
                   (sleep (cdr pair)))
         *song*)))))

As part of the quit process, I have that thread destroyed. There's no problem quitting the app, it's just when re-starting that I get the error.

Any suggestions would be greatly appreciated.

答案1

得分: 2

出现的问题现在已经固定了(能够启动和重新启动多次,没有错误)。

我犯了一个新手错误,将字体初始化放在了描述中提到的WITH-INIT宏的主体之外。

我希望这对于任何使用lispbuilder-sdl并且与C外部对象有困难的人都有用。

英文:

Appears fixed now (able to start and re-start several times without error).

I made a rookie mistake of initialising the fonts outside the body of the WITH-INIT macro mentioned in the description.

I hope this will be useful to anyone using lispbuilder-sdl and struggling with C foreign objects.

huangapple
  • 本文由 发表于 2023年6月8日 02:27:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定