TIC-80
TIC-80 copied to clipboard
scheme_map() improperly handles optional arguments leading to segfault
backtrace
#0 0x00007ffff5d30fd2 in s7_integer (p=0x0) at /home/andrei/Descărcări/TIC-80/vendor/s7/s7.c:13503
#1 0x00007ffff5e6fddf in scheme_map (sc=0x19fe820, args=0x1a02490) at /home/andrei/Descărcări/TIC-80/src/api/scheme.c:306
#2 0x00007ffff5d48f25 in eval (sc=sc@entry=0x19fe820, first_op=first_op@entry=428) at /home/andrei/Descărcări/TIC-80/vendor/s7/s7.c:90407
#3 0x00007ffff5dd0b24 in s7_call (sc=0x19fe820, func=0x1f09b30, args=0x1a02490) at /home/andrei/Descărcări/TIC-80/vendor/s7/s7.c:52883
#4 0x0000000000442e5f in tick (run=0x76fa10) at /home/andrei/Descărcări/TIC-80/src/studio/screens/run.c:106
#5 tick (run=0x76fa10) at /home/andrei/Descărcări/TIC-80/src/studio/screens/run.c:99
#6 0x000000000040f85d in renderStudio (studio=0x7ffff55c7010) at /home/andrei/Descărcări/TIC-80/src/studio/studio.c:2113
#7 studio_tick (studio=0x7ffff55c7010, input=...) at /home/andrei/Descărcări/TIC-80/src/studio/studio.c:2416
#8 0x00000000004093b6 in gpuTick () at /home/andrei/Descărcări/TIC-80/src/system/sdl/main.c:1751
#9 start (argc=<optimized out>, argv=<optimized out>, folder=<optimized out>) at /home/andrei/Descărcări/TIC-80/src/system/sdl/main.c:1969
#10 0x00007ffff782a4d8 in __libc_start_call_main () from /nix/store/lmn7lwydprqibdkghw7wgcn21yhllz13-glibc-2.40-66/lib/libc.so.6
#11 0x00007ffff782a59b in __libc_start_main_impl () from /nix/store/lmn7lwydprqibdkghw7wgcn21yhllz13-glibc-2.40-66/lib/libc.so.6
#12 0x0000000000408395 in _start ()
Steps to Reproduce:
Run this scheme program in TIC-80. The entire TIC-80 program with segfault.:
;;e;; title: HeartTale
;; author: Andrei Șova
;; desc: Undertale if it was made in TIC-80
;; site: N/A
;; license: MIT License
;; version: 0.1
;; script: scheme
(define-macro (inc! x dx) `(set! ,x (+ ,x ,dx)))
(define-macro (get-field f o) `(cdr (assoc ,f ,o)))
(define-macro (append-field! f v o) `(set-field! ,f (cons ,v (get-field ,f ,o)) ,o))
(define (deep-copy x)
())
(define (set-field! f v o)
(let ((pair (assq f o)))
(if pair
(set-cdr! pair v)
(set! o (cons (cons f v) o))))
o)
(define (die str)
(t80::trace (string-append "Error: " str) 3)
(t80::exit))
(define scenes '())
(define current-scene '())
(define (button-down keyname)
(case keyname
((upKey) (t80::btn 0))
((downKey) (t80::btn 1))
((leftKey) (t80::btn 2))
((rightKey) (t80::btn 3))
((aKey) (t80::btn 4))
((bKey) (t80::btn 5))
(else #f)))
(define (scene-load name scenes)
(if (null? scenes) (die "scene not found"))
(if (string=? (get-field 'name (car scenes)) name)
(let ((scene (car scenes)))
(t80::trace (string-append "Loading scene: " name))
(set! current-scene scene)
;; run the onLoad hooks
(for-each (lambda (x) (x scene)) (get-field 'onLoad scene)))
(scene-load name (cdr scenes))))
(define (scene-create name)
(let ((new-scene `((name . ,name)
(objects . ())
(t . 0)
(onLoad . ())
(onTick . ()))))
(set! scenes (append scenes (list new-scene))) new-scene))
(define (gameobject-create x y onTick)
`((pos . (,x ,y))
(onTick . (list ,onTick))))
(define (BOOT)
(t80::poke #x7FC3F 1 1) ;; hide mouse
(t80::trace "The power of TIC-80 fills you with DETERMINATION" 3)
(set-field! 'name "wow" (scene-create "menu"))
(append-field! 'onLoad (lambda (scene) (t80::trace "scene loaded!")) (list-ref scenes 0))
(t80::trace (get-field 'name (list-ref scenes 0)))
(scene-load "wow" scenes))
(define (TIC)
(t80::cls 0)
(t80::map)
(set-field! 't (+ 1 (get-field 't current-scene)) current-scene)
(for-each (lambda (x) (x current-scene)) (get-field 'onTick current-scene))
(for-each (lambda (object)
(for-each (lambda (x) (x object))
(get-field 'onTick object)))
(get-field 'objects current-scene))
;; (t80::spr 256 x y 0 1 0 0 1 1)
;; (t80::print "HELLO WORLD!" 84 84)
;;(inc! t 1)
)
;; <TILES>
;; 001:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
;; 002:0000000e000000ee00000eee0000eeee000eeeee00eeeeee0eeeeeeeeeeeeeee
;; 003:e0000000ee000000eee00000eeee0000eeeee000eeeeee00eeeeeee0eeeeeeee
;; 004:0004044400044444004444440444444444444444044444440444444444444444
;; 005:4000000044004000444440004444440044444400444444404444444044444440
;; 016:0700007070000007700070070000070000700700070007000700000000000000
;; 017:4444444444444444444444444444444444444444444444444444444444444444
;; 018:eeeeeeee0eeeeeee00eeeeee000eeeee0000eeee00000eee000000ee0000000e
;; 019:eeeeeeeeeeeeeee0eeeeee00eeeee000eeee0000eee00000ee000000e0000000
;; 020:4444444444444444044444444444444404444444004444440004044400000000
;; 021:4444444444444440444444444444440044404400444040004400000040000000
;; </TILES>
;; <SPRITES>
;; 000:0000000002202200222222202222222002222200002220000002000000000000
;; 001:0000000002202200220222202220222002022200000220000002000000000000
;; 002:0000000002202200220020200200002002020000000220000002000000000000
;; 003:00000000000c000000ccc00000cccc0000cccccc00cc0ccc00cccccc00cccc0c
;; 004:00000000000c000000ccc00000cccc00cccccc00ccc0cc00cccccc000c0ccc00
;; 005:00cccccc0c0000000c0cc0000c0cc00c0c0000000cc00000000cc0cc00c00c00
;; 006:cccccc00000000c0000cc0c0c00cc0c0000000c000000cc0cc0cc00000c00c00
;; 007:0000000000cccccc0c0000000c0ccccc0c0c00000c0c0cc00c0c00c00c0cccc0
;; 008:00000000cc00000000c00000c0c00000c0c00000c0c00000c0c00000c0c0c00c
;; 016:0000000000110000001100000011000001100000011000000110000000100000
;; 017:0000000000110000001100000011000001100000011000000110000000100000
;; 018:0000000000110000001100000011000001100000011000000110000000100000
;; 019:00ccccc0000ccccc000000cc000ccccc00cccccc00ccccc000ccc00000000000
;; 020:c0cccc00ccccc000cc000000ccccc000cccccc000ccccc00000ccc0000000000
;; 021:00c00c0000c00c00000000cc0000cc000000cc000000cc000000cc0000000000
;; 022:00c00c0000c00c00cc00000000cc000000cc000000cc000000cc000000000000
;; 023:0c0000000c0ccccc0c00000000cccccc00000000000000000000000000000000
;; 024:c0c0ccc0c0c0ccc000ccc0c0ccccccc0cccccc00cccccc000000000000000000
;; 032:0010000000000000000000000000000000000000000000000000000000000000
;; 033:0011000000110000001100000000000000000000000000000000000000000000
;; 034:0011000000110000001100000001100000011000000110000000100000000000
;; 035:00000000cc0000000ccc000000ccc000000cee000000ef00000000f000000000
;; 036:00000000333333333f3f33f33f333ff33f3f33f3333333330003300000033000
;; 037:0000000000000000000000000111100001111000011110400111444000044400
;; 038:0000c00c00c0cccc0cc0cfcf0c00cccc0ccccffc00cccccc00ccccc000c0c0c0
;; 039:0000000000040000000440000044440044444444004444000004400000040000
;; 040:0000000000040000040440400044440044444444004444000404404000040000
;; 041:0000000040040004040440400044440044444444004444000404404040040004
;; 042:0000400000444400044cc44004cccc40044cc400004464000006500000666000
;; 048:00000000000000000dcccc000ccccc000ccccc000ccccc000ccccccc0ccccccc
;; 049:000000000000000000ccccc000ccccc000ccccc000ccccc0ccccccc0ccccccc0
;; 050:00000000000000000dcccccc0ccccccc0ccccccc0ccc00000ccc00000ccccccc
;; 051:0000000000000000ccc00dccccc00cccccc00ccc00000ccc00000cccccc00ccc
;; 052:0000000000000000ccccccc0cccccccccccccccccd00cccccd00cccccccccccc
;; 053:000000000000000000cccccc00cccccc00cccc2c00ccc22200cccc2200ccccc2
;; 054:0000000000000000cccccd00cccccc002ccccc0022cccc002ccccc00cccccc00
;; 055:0000000000000000dccccccccccccccccccccccccccccccccccccccc0000cccc
;; 056:0000000000000000cccccc00cccccc00cccccc00cccccc00cccccc00cc000000
;; 057:0000000000000000dccccccccccccccccccccccccccccccccccccccc0000cccc
;; 058:0000000000000000cccccc00cccccc00cccccc00cccccc00cccccc00cc000000
;; 059:0000000000000000dcccccccccccccccccccccccccccd00cccccd00ccccccccc
;; 060:0000000000000000cc000dccccc00cccccc00cccccc00cccccc00cccccc00ccc
;; 061:0000000000000000cc000000cc000000cc000000cc000000cc000000cc000000
;; 062:00000000000000000dcccccc0ccccccc0ccccccc0ccc00000ccc00000ccccccc
;; 063:0000000000000000cc000000cc000000cc0000000000000000000000cc000000
;; 064:0ccccccc0ccccccc0ccccc000ccccc000ccccc000ccccc000ccccc0000000000
;; 065:ccccccc0cdccccc000ccccc000ccccc000ccccc000ccccc000ccccc000000000
;; 066:0ccccccc0ccccccc0ccc00000ccc00000ccccccc0ccccccc0ccccccc00000000
;; 067:ccc00cccccc00ccc00000ccc00000cccccc00cccccc00cccccd00ccc00000000
;; 068:cccccccccccdccccc000ccccc000ccccc000ccccc000ccccc000cccc00000000
;; 069:00cccccc00cccccc00cccccc00cccddc00ccc00000ccc00000ccc00000000000
;; 070:cccccc00cccccc00cccccc00cccd0000cccd00000ccccc0000cccc0000000000
;; 071:0000cccc0000cccc0000cccc0000cccc0000cccc0000cccc0000cccc00000000
;; 072:cc000000cc000000cc000000cc000000cc000000cc000000cc00000000000000
;; 073:0000cccc0000cccc0000cccc0000cccc0000cccc0000cccc0000cccc00000000
;; 074:cc000000cc000000cc000000cc000000cc000000cc000000cc00000000000000
;; 075:ccccccccccccccdccccc000ccccc000ccccc000ccccc000ccccc000c00000000
;; 076:ccc00cccccc00cccccc00cccccc00cccccc00cccccc00cccccc00ccc00000000
;; 077:cc000000cc000000cc000000ccccccc0ccccccc0ccccccc0ccccccc000000000
;; 078:0ccccccc0ccccccc0ccc00000ccc00000ccccccc0ccccccc0ccccccc00000000
;; 079:cc000000cc0000000000000000000000cc000000cc000000cd00000000000000
;; 080:0000000000000ccc000ccccc000ccffc000ccffc0000cccc000ccfcc0000cfff
;; 081:00000000ccc00000ccccc000cffcc000cffcc000cccc0000ccfcc000fffc0000
;; 094:0000000000000000000000000000ccc00000ccc0000ccccc000cc000000cc000
;; 095:0000000000000000000000000000c00000cc0000ccc00000ccc00000ccccc000
;; 096:000099990009999900c9999900c9ffff000fffff000fffff0000cc00000ccc00
;; 097:999900009999900099999c00ffff9c00fffff000fffff00000cc000000ccc000
;; 106:0000000000000004004440440044444c04444c110444cc1104441ccc044cc111
;; 107:00000000444004004444444044444440c11c4400c11cc444cccc14441111c444
;; 108:0000000000000004004440440044444c04444ccc0444cccc0444cccc044ccccc
;; 109:00000000444004004444444044444440cccc4400ccccc444ccccc444ccccc444
;; 110:000cc00000cccccc00cc000c0ccc00000cc0000c00c000cc00c000c0000c00c0
;; 111:c000c000c000c000c000c00000ccc000ccccc0000000c0000000000000000000
;; 112:11111111444444444ff44ff444444444044ff440004444000777777066666666
;; 113:0000000011111111444444444ff44ff444444444044ff4400044440066666666
;; 114:11111111444444444ff44ff444444444044ff440004444000777777066666666
;; 115:00111100001444400014f4400014440000044f00000444000007700000666600
;; 116:0000000000111100001444400014f4400014440000044f000004440000666600
;; 117:00111100001444400014f4400014440000044f00000444000007700000666600
;; 122:04444c11044444cc004444440044044400000066000006600000066000055566
;; 123:111cc444ccc44440444444404440440000000000000000000000000060000000
;; 124:0444444c04444444004444440044044400000066000006600000066000055566
;; 125:cc4cc44444444440444444404440440000000000000000000000000060000000
;; 126:00cccccc000ccccc00cc4c4c00c444440ccc444c0cccc4cc0c000cc0000cccc0
;; 127:0000000000000000c0000000c000000000000000cc000000ccc00000cccc0000
;; 128:7777777746666664077777700666666004400440044004400880088000000000
;; 129:7777777746666664077777700666666004400440044008800880000000000000
;; 130:7777777746666664077777700666666004400440088004400000088000000000
;; 131:0074770000646600007777000006600000044000000440000008800000000000
;; 132:0074770000664600007777000006600000044000004004000800080000000000
;; 133:0074770000466600007777000006600000044000004040000080800000000000
;; 140:0005500600000006000000000000000600000066000006660000066600000000
;; 141:6000000066550000665500006550000066000000660000006600000000000000
;; 142:00cc0ccc00c000cc00cc00cc00c0cccc00000cc000000ccc000000cc00000000
;; 143:ccccc000c00c0000cc0000000c0000000ccc000000cc0000c0cc000000000000
;; 144:1111111111111111411141444414444404444440004444000777777066666666
;; 145:0000000011111111111111114111414444144444044444400044440066666666
;; 146:1111111111111111411141444414444404444440004444000777777066666666
;; </SPRITES>
;; <MAP>
;; 004:000020101010300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;; 005:000010401150101010101010101010103000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;; 006:000010411151101010101010101010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;; 007:000021101010310000000000000000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;; 008:000000000000000000000000000000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;; 009:000000000000000000000000000000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;; </MAP>
;; <WAVES>
;; 000:000011223456789aaaaaaa9875421000
;; 001:0123456789abcdefedcba98765432100
;; 002:0123456789abcdef0123456789abcdef
;; 003:88888888222222222222222288888888
;; 004:0123456789abcccccccccccccccccccc
;; </WAVES>
;; <SFX>
;; 000:0011005400a7f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000605000000000
;; 001:000500030002000100010000000000001000100050009000b000d000d000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000302000000000
;; 002:020a021b022c024d026f029202b4f207f200f200f200f200f200f200f200f200f200f200f200f200f200f200f200f200f200f200f200f200f200f20040b000000000
;; 003:040004000400040004000400040004000400040004000400040004000400040004000400040004000400040004000400040004000400040004000400502000000000
;; 004:010001000100010001000100210051007100a100c100d100f100f100f100f100f100f100f100f100f100f100f100f100f100f100f100f100f100f100405000000000
;; </SFX>
;; <PATTERNS>
;; 000:500036000010000010000000900036000000000000000000000000000000000000000000a00036000000000000000000000000000000000000000000600036000000000000000000a00036000000000000000000600036000000000000000000700036000000000000000000b00036000000000000000000700036000000000000000000c00036000000000000000000600036000000000000000000900036000000000000000000700036000000000000000000d00030100000000000000000
;; 001:900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000900044000000000000000000600036000000000000000000600044000000000000000000600044000000000000000000600044000000000000000000
;; 002:100030000000100030000000100030000000700038000000900038000000a00038000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
;; </PATTERNS>
;; <TRACKS>
;; 000:180000180000180000180000180000000000000000000000000000000000000000000000000000000000000000000000000000
;; </TRACKS>
;; <PALETTE>
;; 000:0000005d275dfa0000ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
;; </PALETTE>
I also encountered this, I think. I mean, I only added a (t80::map) (without other parameters) after the (t80::cls 13) line from the default template and TIC-80 crashed. It does not crash if I do the same to the lua template.