-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createEvent broken by mutating strings #77
Comments
are there any fixes for this? its becoming a serious issues for very well typesetted subs like [μtw-Kaleido] releases, which can be shown here: |
Can confirm this still happens with current master. And even worse, if you add another event all strings in the previously created events change to the newly added string. This appears to be an issue with improperly passing memory/pointers from JS to WASM. On a side note though, you should not create events with a non-unique ReadOrder value. Your example sets |
@TFSThiagoBR98: Seems like you added this in ec21ec3, do you know what the "best practce"-way of passing strings from JS to WASM is? This likely affects more than just |
WebIDL uses this 2 generated functions: void EMSCRIPTEN_KEEPALIVE emscripten_bind_ASS_Event_set_Text_1(ASS_Event* self, char* arg0) {
self->Text = arg0;
} and its JS counterpart: ASS_Event.prototype['set_Text'] = ASS_Event.prototype.set_Text = /** @suppress {undefinedVars, duplicate} */function(arg0) {
var self = this.ptr;
ensureCache.prepare();
if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr;
else arg0 = ensureString(arg0);
_emscripten_bind_ASS_Event_set_Text_1(self, arg0);
}; Also the function ensureString(value) {
if (typeof value === 'string') {
var intArray = intArrayFromString(value);
var offset = ensureCache.alloc(intArray, HEAP8);
ensureCache.copy(intArray, HEAP8, offset);
return offset;
}
return value;
} This uses the intArrayFromString function but Emscripten also have the stringToUTF8, see here |
so any chance this will get fixed? |
From @TheOneric: For most libass APIs the char* strings remain owned by the caller with libass doing internal copies if needed. This means the caller must if necessary free the memory at some point after the libass API call finished. The track and event modification/creation APIs are different because they work close to library internals (which is also why their usage comes with more restrictions/obligations than other APIs and why they don't sensibly work with ass.h alone). Since we transfer ownership of the pointer to libass, this is unlikely to cause memory leaks.
Currently the ensureCache create a temporary pointer that will transfer the value to the WASM/C part and recycle it with to use in the next value, but since the libass struct pointers are owned by the library, the pointers can't be recycled or freed or can lead into an undefined behavior. This patch allocate new memory and copy the pointer before set into struct attribute. To avoid creating complex code, I decided to fix it in the webidl binder, but i plan to make a way to mark if the attribute need to copy the pointer.
Currently the ensureCache create a temporary pointer that will transfer the value to the WASM/C part and recycle it with to use in the next value, but since the libass struct pointers are owned by the library, the pointers can't be recycled or freed or can lead into an undefined behavior. This configure the binder to tranfer the pointer ownership instead of recycle it. To avoid creating complex code, I decided to fix it in the webidl binder.
Currently the ensureCache create a temporary pointer that will transfer the value to the WASM/C part and recycle it with to use in the next value, but since the libass struct pointers are owned by the library, the pointers can't be recycled or freed or can lead into an undefined behavior. This configure the binder to tranfer the pointer ownership instead of recycle it. To avoid creating complex code, I decided to fix it in the webidl binder.
Fix Events and Styles String Mutation, closes #77
adding an event with createEvent
for some reason creates an event that looks like:
breaking the entire renderer, adding more subtitles with the createEvent function overwrites the text, effect and name values of the previous events
The text was updated successfully, but these errors were encountered: