Comments (9)
I will note I'm not an expert in that area- I just couldn't find anything that looked wrong.
from rlua.
Thanks for the report, and especially for the small example! I can reproduce it here.
The fact that there's no unsafe in the example means the bug must be either in rlua or Quat
- I'll look into it.
from rlua.
rlua already uses an allocation function (to track allocation totals), but this doesn't help as userdata is stored internally to Lua with a header which messes up the alignment in this case.
As far as pointers to fields of userdata, it would be difficult to avoid Rust undefined behaviour by e.g. accidentally having an &mut
reference at the same time as another reference, for example when calling a method. I think the answer would be the same as if you wanted to keep references to something a different Rust library kept in a Box<T>
which it kept ownership of.
However you can implement UserData
on Arc<T>
, and then you can legally keep another copy of the Arc
outside (at the cost of the reference counting and extra indirection of course).
from rlua.
Interestingly this happens identically for the Vec4 from glam as well. I think this might something to do with alignment and size of these structures.
This was spot on - it turns out that with the default configuration (LUAI_MAXALIGN
) Lua only guarantees 8 byte alignment for userdata. The crash (at least on my x86-64 system) is because Quat::clone()
is using the movaps
instruction which assumes 16-byte alignment but the Quat
is only 8 byte aligned.
I could try to increase LUAI_MAXALIGN
, but that would only push the potential problem to the next size up - I think the correct fix will be to compensate in the Lua code where the correct alignment is known.
from rlua.
That's very interesting! I noticed there is a possibility to use a custom allocation function, would that be of any use here ?
Also while I have your attention, since the UserData's are stored directly in lua, is it safe to keep and use pointers to fields of UserData managed on the Lua side (say a UserData like MyUserData
in this case, but assuming it's alive at that point)
from rlua.
@makspll you should try mlua instead, it works fine on your example, no segfault.
from rlua.
Hi,
I believe #254 fixes this issue. I will merge it and kick off a release in the next few days if I don't hear otherwise.
Thanks again for the report!
from rlua.
I've released rlua 0.19.2 with this fix.
from rlua.
Sorry for late response,
This seems to fix my issue! Fantastic work!
from rlua.
Related Issues (20)
- Possible bug with __newindex not called on numeric indexing HOT 4
- Question: How to exec multiple things at once? HOT 4
- ios build error HOT 7
- examples for error handling HOT 2
- Example for eval return a struct? HOT 1
- Cannot load DLLs in v0.19 HOT 6
- Missing mutable borrows for Table<'lua> HOT 2
- Context.create_sequence_from should support references HOT 1
- Undefined symbol lua_checkstack HOT 8
- Crash on empty source HOT 2
- custom runtime path HOT 3
- creating a `require`-able module HOT 8
- [Request] UserData::from_lua HOT 1
- Suggestion: proc_macro for LuaUserDataMethods::add_method HOT 3
- No documentation on how to use LuaRocks with rlua HOT 3
- Rlua + Luarocks Modules -> Fail to load HOT 3
- Memory leak when using system-luajit HOT 2
- Merge with mlua HOT 32
- [Typo] Example says laoded(instead of loaded) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rlua.