Skip to content

Fix two crashes#130

Merged
Smu1zel merged 1 commit intoerievs:mainfrom
RaydanOMGr:fix/crash
Dec 28, 2025
Merged

Fix two crashes#130
Smu1zel merged 1 commit intoerievs:mainfrom
RaydanOMGr:fix/crash

Conversation

@RaydanOMGr
Copy link

Crash 1 (at network_downloader.cpp:61): This crash happened when the app would attempt to copy the vector data to put it into the map. This fix is technically more of a workaround, as it prevents the vector from getting copied, and instead converts it into a rvalue by std::moving it, which means it doesn't need to be copied and can directly be put into the map

Crash 2 (at draw.cpp:123): This crash would happen when the code attempted to set c2d_image->subtex->top to 1.0. This happened because Draw_c2d_image_init didn't allocate the right amount of memory. Instead of allocating the sizeof(Tex3DS_SubTexture) and sizeof(C3D_Tex), it allocated the size of their pointers, meaning it just allocated 4 bytes two times and not the size of the structure. This meant that in linear space, there would be 8 allocated bytes in a row, which fit the width and height, which are both u16 values, filling 4 bytes, and the left variable, which is a 32-bit float, which is 4 bytes, and fills the allocated RAM. When attempting to set top, which happens at an offset of exactly 8 bytes, it wanders off into unallocated memory, which is known as undefined behavior and leads to random segfaults.

If you have any questions or complaints, please ask, I will be happy to respond and discuss any potential issues, as I am not sure if any of my changes may be break something else in the codebase

Crash 1 (at network_downloader.cpp:61): This crash happened when the app would attempt to copy the vector data to put it into the map. This fix is technically more of a workaround, as it prevents the vector from getting copied, and instead converts it into a rvalue by std::moving it, which means it doesn't need to be copied and can directly be put into the map

Crash 2 (at draw.cpp:123): This crash would happen when the code attempted to set c2d_image->subtex->top to 1.0. This happened because Draw_c2d_image_init didn't allocate the right amount of memory. Instead of allocating the sizeof(Tex3DS_SubTexture) and sizeof(C3D_Tex), it allocated the size of their pointers, meaning it just allocated 4 bytes two times and not the size of the structure. This meant that in linear space, there would be 8 allocated bytes in a row, which fit the width and height, which are both u16 values, filling 4 bytes, and the left variable, which is a 32-bit float, which is 4 bytes, and fills the allocated RAM. When attempting to set top, which happens at an offset of exactly 8 bytes, it wanders off into unallocated memory, which is known as undefined behavior and leads to random segfaults.
@Smu1zel
Copy link
Collaborator

Smu1zel commented Dec 28, 2025

Thank you so much.

@Smu1zel Smu1zel merged commit 6f13ed3 into erievs:main Dec 28, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants