Closed MortimerSnerd closed 1 year ago
So Assertion failed: IsRefNilVar(b.sid->type->t), file C:\src\lobster\dev\src\lobster\typecheck.h, line 2074
is the first thing to check, since all the use after free stuff you found is way later, at runtime, and could be the consequence of that assert.
Easiest if you can somehow give me access to something that reproduces that assert?
From looking at your data it looks like your xyz_f
structs would have a lifetime associated with it, lets see if I can repro with similar code..
This simple program does not repro, so I need either a more complex test, or your full program:
import vec
import std
let seen_norms = [ xyz_1 ]
let p_norm = xyz_1
if (find(seen_norms) nn: nn == p_norm) < 0:
print "foo"
I'll message you in discord with the google drive link in a sec. The main thing I cut out of the picture in the zip file is the large-ish main.lobster. If you run src\smallmain.lobster, it has just a call to the problem function in core\physics.lobster which is enough for me to get the assertion.
Found the type-checker problem. For posterity, what happens is that []
which gets passed into find
is a list of unknown element type (a "type variable"), that then gets passed to nn
which is now a type variable, which then gets registered as possibly a borrowed value in ==
, but then gets bound to be a struct and not something that can be borrowed.
Now to see what is the cleanest solution..
Looks like removing the assert is the only way for now, since we allow borrows on type variables.
Your small main then game/physics.lobster(347): error: unknown field/function reference is_floor_normal
Your regular main runs the actual game, and does not crash. This is in VS Debug mode which normally does pretty thorough memory checks, but I guess not as strong as ASAN.
Ok managed to get repro, fixed in: https://github.com/aardappel/lobster/commit/764661230bf8524b48c62248fc2ed41803c675ea
The problem was the code generator got confused between the number of return values declared, vs the ones actually requested by the caller.
I pulled the latest on master, 56ed7897ef3e71513118a0f865ab5b0b8cef4d32
Short summary
I started getting a crash with the lobster release build after changing a data file that I read from a lobster program. The debug version of lobster shows an assertion in type/borrow checking before the program can even run, and the ASAN build runs and shows a use after free.
Details
So I get this in lobster-release.exe.exp.log:
I switched to the debug version of lobster to see if I got an assertion, and I get this:
And I get this in lobster-debug.exe.exp.log:
I poked around in the debugger for a few minutes to see what line of my lobster code it was referencing when it asserted, and it's an innocuous looking find on a [xyz_f]:
I built the asan-release target and run with it, and it detects a use after free (with the byte legend at the end elided):
Other notes about the crash:
This seems complicated enough I doubt it's enough for you to go on. If you need it, I can put together a zip of the files, and PM a gdrive link or something similar.