You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug UiBuffer::scratch_txt_two() calls push() twice and returns 2 pointers. The problem is that the first pointer is pointing to the old buffer when the second push causes a reallocation due to extend. When building in debug mode on MacOS, rustc 1.75, the old pointer, when there is a resize, will point to the old memory which it seems to be zero out (didn't look into the extend implementation) and so the string returned will point to a \0, resulting to a null string. The string is later used as label, which will cause imgui to assert because IDs can't be null.
This is because the initial capacity, at least on the system I've tried, is 0 and it is doubled everytime. Now, when using UiBuffer::scratch_txt_two() if the second txt does not fit into the vector, extend will trigger a reallocation and hold pointer will point to the old memory, which if zero out (like in my case), it will be cause a crash.
To Reproduce
This is reproducible in debug mode. Use the code in #725
Expected behavior
Library shouldn't return an invalid pointer.
Screenshots
Please describe your environment
imgui-rs 0.11
MacOS 14.2.1
Other information
One solution I've found is to instead of allocation the buffer with new() to call with_capacity(max_len) but that requires the method not to be const, which I don't know if it is an acceptable solution.
The text was updated successfully, but these errors were encountered:
Describe the bug
UiBuffer::scratch_txt_two()
calls push() twice and returns 2 pointers. The problem is that the first pointer is pointing to the old buffer when the second push causes a reallocation due to extend. When building in debug mode on MacOS, rustc 1.75, the old pointer, when there is a resize, will point to the old memory which it seems to be zero out (didn't look into theextend
implementation) and so the string returned will point to a\0
, resulting to a null string. The string is later used as label, which will causeimgui
to assert because IDs can't be null.This is because the initial capacity, at least on the system I've tried, is 0 and it is doubled everytime. Now, when using
UiBuffer::scratch_txt_two()
if the second txt does not fit into the vector,extend
will trigger a reallocation and hold pointer will point to the old memory, which if zero out (like in my case), it will be cause a crash.To Reproduce
This is reproducible in debug mode. Use the code in #725
Expected behavior
Library shouldn't return an invalid pointer.
Screenshots
Please describe your environment
Other information
One solution I've found is to instead of allocation the buffer with
new()
to callwith_capacity(max_len)
but that requires the method not to be const, which I don't know if it is an acceptable solution.The text was updated successfully, but these errors were encountered: