英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论