Подпишитесь на наш Telegram-канал, чтобы всегда быть в курсе важных обновлений! Перейти

Вопрос Подскажите как можно через mutex снохронить данные

It's due to the fact that this data is accessed from multiple threads. You need to lock mutex before applying any changes to the data and then unlock once you're done. Or else the program could be manipulating the data while other thread would be in the middle of writing of the same content, and unfinished content would be used, which would mean corrupted data would be used. And that causes crashes.
TUTORIAL:
You simply declare somewhere mutex variable
Код:
Expand Collapse Copy
static std::mutex lock;
You want to have only one instance of this variable for locking the same data, so in this case, I used static expression in this case that will make sure we have only 1 lock instance

Then before you READ or WRITE into variables, arrays, memory in general that is being accessed throughout more than 1 thread. You need to LOCK IT! Since CSGO is multithreaded and if you call something from 2 different hooks, it can happen that the same code would be executed at the same time, which is a problem. So you better be using mutex or some other thread-safety option to protect yourself from undefined behavior
So to lock it you just do this:
Код:
Expand Collapse Copy
lock.lock();


And once you're finished with READING or WRITING, you need to unlock the mutex again. So you can call it next time again. If you leave the lock LOCKED, the program will hang on the lock instruction forever, because it's waiting for another thread to unlock. So remember to UNLOCK the mutex!
To unlock the mutex you just do this:
Код:
Expand Collapse Copy
lock.unlock();
 
Надо для рендера лв, то что я делаю сейчас крашит, и я хз почему
а не проще сделать рендер через 3 драв листа, тогда можно будет вызвать рендер где угодно
пример можешь чекнуть тут:
Пожалуйста, авторизуйтесь для просмотра ссылки.
 
а не проще сделать рендер через 3 драв листа, тогда можно будет вызвать рендер где угодно
пример можешь чекнуть тут:
Пожалуйста, авторизуйтесь для просмотра ссылки.
а не проще, ибо для этого нужно будет отрубать ассерты имгуя, которые, к слову, туда не просто так запихнули
 
and not easier, because for this it will be necessary to chop off imguy assertions, which, by the way, were not just shoved there
I would just use the imgui background draw list
Код:
Expand Collapse Copy
GetBackgroundDrawList()
then there is no need to remove any assertions or modify imgui in any way.
 
а не проще, ибо для этого нужно будет отрубать ассерты имгуя, которые, к слову, туда не просто так запихнули
Будем честны, ничего критичного не случится, убери ты 1 ассерт. Можно запариться чуть больше и не проверять ту структуру если дело имеем с кастомным дроу листом
 
Последнее редактирование:
а не проще, ибо для этого нужно будет отрубать ассерты имгуя, которые, к слову, туда не просто так запихнули
А почему во множественном числе то? Я убирал всего один.
 
Назад
Сверху Снизу