planetis-m / naylib

Yet another raylib Nim wrapper
MIT License
209 stars 11 forks source link

Problem with ownership of shaders and textures #50

Closed planetis-m closed 1 year ago

planetis-m commented 1 year ago

From rmodels UnloadModel:

// NOTE: As the user could be sharing shaders and textures between models,
// we don't unload the material but just free it's maps,
// the user is responsible for freeing models shaders and textures
planetis-m commented 1 year ago

Affected materials[].shader, materials[].maps[].texture, materials[].maps itself is freed!

planetis-m commented 1 year ago

MaterialMap has no destructor, so a "weak" not owning Texture will work fine. BUT Material has destructor and unloads Shader and maps Textures properly! But Model that aggregates all of them...

planetis-m commented 1 year ago

Fixed in a more elegant way than the rust bindings/

planetis-m commented 1 year ago

Model.meshes might be better modeled with WeakModel. But no example exists so who cares.

planetis-m commented 1 year ago

https://github.com/MisterPeModder/Bomberman-Global-Offensive/blob/dfef971b30d0ef82812cb951be7b273c910db35b/src/raylib/model/Model.cpp#L85 Uses a runtime flag instead. Seems from it's usage it always owns the mesh.

https://github.com/nullstare/ReiLua Seem to use shared meshes but mixes both variations! It's def incorrect.

planetis-m commented 1 year ago

No, this is done better as a runtime check and for that to work unloadModelWithoutMesh needs to be available.

planetis-m commented 1 year ago

loadModelFromMesh always sinks the parameter, it could take a bool value.