Skip to content
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

Fix text_unicode.c example crashing #3250

Merged
merged 2 commits into from Aug 19, 2023
Merged

Fix text_unicode.c example crashing #3250

merged 2 commits into from Aug 19, 2023

Conversation

ghost
Copy link

@ghost ghost commented Aug 19, 2023

The issue causing the examples/text/text_unicode.c to crash on PLATFORM_WEB was the Line Feed (LF) char \x0A on some entries of messages[] (L71, L77, L78, L79, L80, L81, L119, L120) not being escaped when being passed to SetClipboardText() (L195). All chars on those messages resolve to a singular unicode char, however, the Line Feed (LF) resolves to \n (with the \ plus n) which causes the unescaped error on web.

This can be solved by escaping the \x0A to \\n before passing it to SetClipboardText() if on PLATFORM_WEB (R195-R202).

@raysan5 Could you please check if that MemFree() call is correct? I saw the warning on the header about TextReplace() (L1417) but I'm not sure if I did that right.

Also (unrelated) small fix to float textOffsetY (R352).

Tested these proposed changes on Chromium (version 115.0.5790.170 64-bit) and Firefox (version 115.1.0esr 64-bit) both running on Linux (Linux Mint 21.1 64-bit).

Fixes #3249.

Edit 1: added line marks.
Edit 2: forgot to add the test environment.

@ghost
Copy link
Author

ghost commented Aug 19, 2023

Follow up issue

There appears to be some other problem on SetClipboardText() for web. Passing an unescaped char to it shouldn't cause the entire program/game to crash on web. Looking at its code (L2150) I expected it just not to finish, but not crashing.

I assembled a minimal reproduction code to test the issue:

#include "raylib.h"

int main(void) {
    InitWindow(800, 450, "test");
    SetTargetFPS(60);
    while (!WindowShouldClose()) {

        // Works
        if (IsKeyPressed(KEY_ONE))   SetClipboardText("1\\n2");

        // Crashes
        if (IsKeyPressed(KEY_TWO))   SetClipboardText("1\n2");

        BeginDrawing();
        ClearBackground(RAYWHITE);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Note: Regardless, the text_unicode.c fix on the PR was still necessary because text_unicode.c should still pass a valid string to SetClipboardText() so it can complete successfully.

@raysan5
Copy link
Owner

raysan5 commented Aug 19, 2023

@ubkp The issue is actually in SetClipboardText(), not properly supporting UTF-8 string data as it should, or at least not on PLATFORM_WEB. I think the easiest solution for this example is just removing that line and related code. It's not needed and I don't know why it is called.

SetClipboardText() on web could be threated as another separate issue.

@ghost
Copy link
Author

ghost commented Aug 19, 2023

@raysan5 Adjusted the fix as instructed (L190, L195).

I'll open a new issue about the SetClipboard().

@raysan5 raysan5 merged commit 016b7d0 into raysan5:master Aug 19, 2023
12 checks passed
@raysan5
Copy link
Owner

raysan5 commented Aug 19, 2023

@ubkp thanks for the review!

@ghost ghost deleted the fix/example-unicode branch August 19, 2023 11:59
raysan5 added a commit that referenced this pull request Sep 17, 2023
* Prettified a comment

* fixed broken indentation caused by another commit.
the commit renamed a bool to int and broke indentation: 233cf39

* Changed 0.001 and 0.00001 to EPSILON
This commit is untested.
I don't know what consequences this has.
Since the commits that added these numbers were before epsilon was added,
I have assumed that epsilon could replace them.

* Prettied up indentation in a few places

* removed spacing around *, standardizing it.

* I may have gotten overboard with indentation

* removed a few useless parenthesis

* Added fortran-raylib

* Fix examples/others/rlgl_standalone.c compilation issue (#3242)

* Update BINDINGS.md

* Ignore unused return value of GetCodepointNext in GetCodepointCount (#3241)

* Ignore unused return value of GetCodepointNext in GetCodepointCount

Removes the last warning from non-external libraries when compiling with
the default build configuration on x64 Linux.

* Remove unnecessary void cast in GetCodepointCount

* Fix #3246

* Revert "Fix #3246"

This reverts commit e4dcbd5.

* Fix text_unicode.c example crashing (#3250)

* Fix text_unicode.c example crashing

* Adjust the text_unicode.c example crashing fix

* tweaks

* add build.zig options for individual modules (#3254)

* Add `IsKeyPressedRepeat` (desktop only) (#3245)

Since the key pressed are handle by comparing current vs previous
state (ie frame), a special way is needed to handle key repeats.

* Reviewed `IsKeyPressedRepeat()` #3248

* Update rcore.c (#3255)

* Match CMakeOptions.txt options default values (#3258)

* Fix SetClipboardText for web (#3257)

* [Image] Validate that ImageDrawRectangleRec is drawing entirely inside the image (#3264)

* Add a function to clone a sound and share data with another sound.

* rename items based on feedback

* PR Feedback, use custom unload for sound alias, not variant of normal sound unloading

* sound_multi example

* Validate that image rect drawing is inside the image so we don't overflow a buffer

* remove files that should not have been added.

* remove changes that should not have been

* revert

* adsfasdfsdfsdf

* Add Vector3 Projecting and Rejection to Raymath (#3263)

* Update raymath.h

* formatting

* [Feature] IsKey... safety checks and more (#3256)

* [Feature] Add GetKeyRepeat

* Update rcore.c

* Simpler design, only one repeat per frame

* Update config.h

* Update rcore.c

* Add KEYBOARD_KEYS_MASK

* Update config.h

* reversions

* Update rcore.c

* Update rcore.c

* change docs

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update raylib.h

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Fix bug where default shaders was not linking. (#3261)

* Formating review

* Add missing cmake options (#3267)

* Fix CMake extraneous -lglfw (#3266)

Closes #3265.

The problem: LIBS_PRIVATE is a list of library names (used by pkg-config), but the shared library of the same name doesn't always exist.

* Fix example/models/models_loading_gltf.c controls (#3268)

* Fix example/models/models_loading_m3d.c controls (#3269)

* Remove e from secondes (#3270)

* Fix example/audio/audio_module_player.c help instructions and small bug (#3272)

* Fix example/audio/audio_module_player.c help instructions and small bug

* Update example/audio/audio_module_player.png screenshot

* Use type name instead of valid specifier

long long --> long long int

* REVIEWED: `GetFileLength()`, added comment #3262

* Update examples/models/models_loading_gltf.png;m3d.png screenshots (#3273)

* Remove a duplicated screenshot and add missing one (#3275)

* Add examples/shaders/shaders_lightmap.c to Makefiles (#3276)

* Fix examples/others/easings_testbed.c help instructions and small tweak (#3277)

* Fix examples/shaders/shaders_texture_outline.c help instructions (#3278)

* Fix examples/shapes/shapes_collision_area.c help instructions (#3279)

* RENAMED: LoadFont*() parameter names for consistency and coherence

* Fix uninitialized thread-locals in stbi #3282 (#3283)

* REVIEWED: Added `SetTextLineSpacing()` to multiline examples

* REVIEWED: Data size type consistency between functions #3168

* Some tweaks

* Use internal default allocators, instead of user-exposed ones

* Added rudimentary SVG support. (#2738)

* Added rudimentary SVG support. Added 2 functions ImageLoadSvg and ImageLoadSvgWithSize.

* Added an example on how to use ImageLoadSvgWithSize and adjusted Makefiles accordingly.

* Added actual correct example file.

* Reviewed the code to keep the raylib coding conventions in mind.
Moved the LoadImageSvg() code into LoadImage() guarded by SUPPORT_FILEFORMAT_SVG.
Renamed LoadImageSvgWithSize() to LoadImageSvg().
Added a LoadImageSvgFromString() function to parse the loaded SVG into an actual image. This does the bulk of the work.

* Fixed typo.

---------

Co-authored-by: Ray <raysan5@gmail.com>

* REVIEWED: `LoadImageSvg()`

* REVIEWED: `LoadImageSvg()`

* Add SUPPORT_FILEFORMAT_SVG to cmake (#3284)

* Fix examples/textures/textures_fog_of_war.c help instructions (#3285)

* Fix examples/textures/textures_image_rotate.c help instructions (#3286)

* Update rtextures.c

* Fix #3247

* Update config.h

* Fix #3293

* Disable UBSAN in zig builds. (#3292)

Zig debug builds automatically enable ubsan.
As the fix for #1891 had to be reverted, debug builds using zig will crash like so:

```
Illegal instruction at address 0x3237d2
raylib/src/rlgl.h:3690:91: 0x3237d2 in rlDrawVertexArrayElements (/home/rcorre/src/raylib-zig-template/raylib/src/rcore.c)
    glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (const unsigned short *)buffer + offset);
```

This disables UBSAN when using zig to build raylib.

* Update README.md (#3290)

specially -> especially

* Update cmake SUPPORT_FILEFORMAT_SVG default value (#3291)

* Mouse offset and scaling must be considered also on web!

* Update rcore.c

* Update Makefile : clean raygui.c & physac.c (#3296)

* Remove PLATFORM_RPI (#3232)

* Remove PLATFORM_RPI

* remove build artifacts

---------

Co-authored-by: MichaelFiber <michael@cubeofb.org>
Co-authored-by: Ray <raysan5@gmail.com>

* Review to avoid UBSAN complaining #1891

* added raylib-raku to bindings (#3299)

* examples: core: adds 2D camera two player split screen (#3298)

* Reviewed examples for consistency

* Update rtext.c

* Some code restructuring for input functions, consistency review

* Remove unneeded #if (#3301)

Co-authored-by: MichaelFiber <michael@cubeofb.org>

* Revert "Disable UBSAN in zig builds. (#3292)" (#3303)

This reverts commit a316f9e.

Issue #1891 was fixed again, so this is no longer needed.

* rtextures: Fix ImageDraw() source clipping when drawing beyond top left (#3306)

* REVIEWED: `TextToPascal()` issue when first char is uppercase

* Implement FLAG_WINDOW_RESIZABLE for web (#3305)

Fixes #3231

* Update BINDINGS.md (#3307)

Fix Kaylib binding. Reroute to a new repository.
Binding renamed.

* Update webassembly.yml

* Add claw-raylib to BINDINGS.md (#3310)

* Add SetWindowMaxSize for desktop and web (#3309)

* Add SetWindowMaxSize for desktop and web

* Remove SizeInt and respective adjustments

* Update rtextures.c

* Reviewed parameters for consistency

* Rename windowM* to screenM* (#3312)

* Update BINDINGS.md (#3317)

Update TurboRaylib bindings

* Update rmodels.c

* Update BINDINGS.md with vaiorabbit/raylib-bindings (#3318)

* fixed spelling mistake

* put back parenthesis

* reverted major allignment changes

* reverted parser output changes

* reverted one more indentation change

---------

Co-authored-by: Brian-E <brian@intra.fo>
Co-authored-by: Ray <raysan5@gmail.com>
Co-authored-by: ubkp <118854183+ubkp@users.noreply.github.com>
Co-authored-by: ashn <60763262+ashn-dot-dev@users.noreply.github.com>
Co-authored-by: actondev (Christos) <chris.actondev@gmail.com>
Co-authored-by: vitopigno <103512727+VitusVeit@users.noreply.github.com>
Co-authored-by: Asdqwe <asdqwe@asdqwe.com>
Co-authored-by: Jeffery Myers <jeffm2501@gmail.com>
Co-authored-by: Ethan Simpson <ethansimpson@xtra.co.nz>
Co-authored-by: Nickolas McDonald <43690021+n77y@users.noreply.github.com>
Co-authored-by: Branimir Ričko <rickobranimir@gmail.com>
Co-authored-by: iacore <74560659+iacore@users.noreply.github.com>
Co-authored-by: Ethan Conneely <Econn50@outlook.com>
Co-authored-by: Johannes Barthelmes <615914+jbarthelmes@users.noreply.github.com>
Co-authored-by: bXi <bluepunk@gmail.com>
Co-authored-by: Ryan Roden-Corrent <ryan@rcorre.net>
Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com>
Co-authored-by: SuperUserNameMan <yoann@terminajones.com>
Co-authored-by: MichaelFiber <42419558+michaelfiber@users.noreply.github.com>
Co-authored-by: MichaelFiber <michael@cubeofb.org>
Co-authored-by: Dan Vu <danvu.hustle@gmail.com>
Co-authored-by: Gabriel dos Santos Sanches <gabrielssanches@gmail.com>
Co-authored-by: Rob Loach <robloach@gmail.com>
Co-authored-by: Peter0x44 <peter0x44@disroot.org>
Co-authored-by: Kenta <106167071+Its-Kenta@users.noreply.github.com>
Co-authored-by: bohonghuang <1281299809@qq.com>
Co-authored-by: turborium <45082001+turborium@users.noreply.github.com>
Co-authored-by: Wilson Silva <wilson.dsigns@gmail.com>
futureapricot pushed a commit to futureapricot/raylib that referenced this pull request Oct 4, 2023
* Fix text_unicode.c example crashing

* Adjust the text_unicode.c example crashing fix
futureapricot pushed a commit to futureapricot/raylib that referenced this pull request Oct 4, 2023
* Prettified a comment

* fixed broken indentation caused by another commit.
the commit renamed a bool to int and broke indentation: 233cf39

* Changed 0.001 and 0.00001 to EPSILON
This commit is untested.
I don't know what consequences this has.
Since the commits that added these numbers were before epsilon was added,
I have assumed that epsilon could replace them.

* Prettied up indentation in a few places

* removed spacing around *, standardizing it.

* I may have gotten overboard with indentation

* removed a few useless parenthesis

* Added fortran-raylib

* Fix examples/others/rlgl_standalone.c compilation issue (raysan5#3242)

* Update BINDINGS.md

* Ignore unused return value of GetCodepointNext in GetCodepointCount (raysan5#3241)

* Ignore unused return value of GetCodepointNext in GetCodepointCount

Removes the last warning from non-external libraries when compiling with
the default build configuration on x64 Linux.

* Remove unnecessary void cast in GetCodepointCount

* Fix raysan5#3246

* Revert "Fix raysan5#3246"

This reverts commit e4dcbd5.

* Fix text_unicode.c example crashing (raysan5#3250)

* Fix text_unicode.c example crashing

* Adjust the text_unicode.c example crashing fix

* tweaks

* add build.zig options for individual modules (raysan5#3254)

* Add `IsKeyPressedRepeat` (desktop only) (raysan5#3245)

Since the key pressed are handle by comparing current vs previous
state (ie frame), a special way is needed to handle key repeats.

* Reviewed `IsKeyPressedRepeat()` raysan5#3248

* Update rcore.c (raysan5#3255)

* Match CMakeOptions.txt options default values (raysan5#3258)

* Fix SetClipboardText for web (raysan5#3257)

* [Image] Validate that ImageDrawRectangleRec is drawing entirely inside the image (raysan5#3264)

* Add a function to clone a sound and share data with another sound.

* rename items based on feedback

* PR Feedback, use custom unload for sound alias, not variant of normal sound unloading

* sound_multi example

* Validate that image rect drawing is inside the image so we don't overflow a buffer

* remove files that should not have been added.

* remove changes that should not have been

* revert

* adsfasdfsdfsdf

* Add Vector3 Projecting and Rejection to Raymath (raysan5#3263)

* Update raymath.h

* formatting

* [Feature] IsKey... safety checks and more (raysan5#3256)

* [Feature] Add GetKeyRepeat

* Update rcore.c

* Simpler design, only one repeat per frame

* Update config.h

* Update rcore.c

* Add KEYBOARD_KEYS_MASK

* Update config.h

* reversions

* Update rcore.c

* Update rcore.c

* change docs

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update raylib.h

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Update rcore.c

* Fix bug where default shaders was not linking. (raysan5#3261)

* Formating review

* Add missing cmake options (raysan5#3267)

* Fix CMake extraneous -lglfw (raysan5#3266)

Closes raysan5#3265.

The problem: LIBS_PRIVATE is a list of library names (used by pkg-config), but the shared library of the same name doesn't always exist.

* Fix example/models/models_loading_gltf.c controls (raysan5#3268)

* Fix example/models/models_loading_m3d.c controls (raysan5#3269)

* Remove e from secondes (raysan5#3270)

* Fix example/audio/audio_module_player.c help instructions and small bug (raysan5#3272)

* Fix example/audio/audio_module_player.c help instructions and small bug

* Update example/audio/audio_module_player.png screenshot

* Use type name instead of valid specifier

long long --> long long int

* REVIEWED: `GetFileLength()`, added comment raysan5#3262

* Update examples/models/models_loading_gltf.png;m3d.png screenshots (raysan5#3273)

* Remove a duplicated screenshot and add missing one (raysan5#3275)

* Add examples/shaders/shaders_lightmap.c to Makefiles (raysan5#3276)

* Fix examples/others/easings_testbed.c help instructions and small tweak (raysan5#3277)

* Fix examples/shaders/shaders_texture_outline.c help instructions (raysan5#3278)

* Fix examples/shapes/shapes_collision_area.c help instructions (raysan5#3279)

* RENAMED: LoadFont*() parameter names for consistency and coherence

* Fix uninitialized thread-locals in stbi raysan5#3282 (raysan5#3283)

* REVIEWED: Added `SetTextLineSpacing()` to multiline examples

* REVIEWED: Data size type consistency between functions raysan5#3168

* Some tweaks

* Use internal default allocators, instead of user-exposed ones

* Added rudimentary SVG support. (raysan5#2738)

* Added rudimentary SVG support. Added 2 functions ImageLoadSvg and ImageLoadSvgWithSize.

* Added an example on how to use ImageLoadSvgWithSize and adjusted Makefiles accordingly.

* Added actual correct example file.

* Reviewed the code to keep the raylib coding conventions in mind.
Moved the LoadImageSvg() code into LoadImage() guarded by SUPPORT_FILEFORMAT_SVG.
Renamed LoadImageSvgWithSize() to LoadImageSvg().
Added a LoadImageSvgFromString() function to parse the loaded SVG into an actual image. This does the bulk of the work.

* Fixed typo.

---------

Co-authored-by: Ray <raysan5@gmail.com>

* REVIEWED: `LoadImageSvg()`

* REVIEWED: `LoadImageSvg()`

* Add SUPPORT_FILEFORMAT_SVG to cmake (raysan5#3284)

* Fix examples/textures/textures_fog_of_war.c help instructions (raysan5#3285)

* Fix examples/textures/textures_image_rotate.c help instructions (raysan5#3286)

* Update rtextures.c

* Fix raysan5#3247

* Update config.h

* Fix raysan5#3293

* Disable UBSAN in zig builds. (raysan5#3292)

Zig debug builds automatically enable ubsan.
As the fix for raysan5#1891 had to be reverted, debug builds using zig will crash like so:

```
Illegal instruction at address 0x3237d2
raylib/src/rlgl.h:3690:91: 0x3237d2 in rlDrawVertexArrayElements (/home/rcorre/src/raylib-zig-template/raylib/src/rcore.c)
    glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, (const unsigned short *)buffer + offset);
```

This disables UBSAN when using zig to build raylib.

* Update README.md (raysan5#3290)

specially -> especially

* Update cmake SUPPORT_FILEFORMAT_SVG default value (raysan5#3291)

* Mouse offset and scaling must be considered also on web!

* Update rcore.c

* Update Makefile : clean raygui.c & physac.c (raysan5#3296)

* Remove PLATFORM_RPI (raysan5#3232)

* Remove PLATFORM_RPI

* remove build artifacts

---------

Co-authored-by: MichaelFiber <michael@cubeofb.org>
Co-authored-by: Ray <raysan5@gmail.com>

* Review to avoid UBSAN complaining raysan5#1891

* added raylib-raku to bindings (raysan5#3299)

* examples: core: adds 2D camera two player split screen (raysan5#3298)

* Reviewed examples for consistency

* Update rtext.c

* Some code restructuring for input functions, consistency review

* Remove unneeded #if (raysan5#3301)

Co-authored-by: MichaelFiber <michael@cubeofb.org>

* Revert "Disable UBSAN in zig builds. (raysan5#3292)" (raysan5#3303)

This reverts commit a316f9e.

Issue raysan5#1891 was fixed again, so this is no longer needed.

* rtextures: Fix ImageDraw() source clipping when drawing beyond top left (raysan5#3306)

* REVIEWED: `TextToPascal()` issue when first char is uppercase

* Implement FLAG_WINDOW_RESIZABLE for web (raysan5#3305)

Fixes raysan5#3231

* Update BINDINGS.md (raysan5#3307)

Fix Kaylib binding. Reroute to a new repository.
Binding renamed.

* Update webassembly.yml

* Add claw-raylib to BINDINGS.md (raysan5#3310)

* Add SetWindowMaxSize for desktop and web (raysan5#3309)

* Add SetWindowMaxSize for desktop and web

* Remove SizeInt and respective adjustments

* Update rtextures.c

* Reviewed parameters for consistency

* Rename windowM* to screenM* (raysan5#3312)

* Update BINDINGS.md (raysan5#3317)

Update TurboRaylib bindings

* Update rmodels.c

* Update BINDINGS.md with vaiorabbit/raylib-bindings (raysan5#3318)

* fixed spelling mistake

* put back parenthesis

* reverted major allignment changes

* reverted parser output changes

* reverted one more indentation change

---------

Co-authored-by: Brian-E <brian@intra.fo>
Co-authored-by: Ray <raysan5@gmail.com>
Co-authored-by: ubkp <118854183+ubkp@users.noreply.github.com>
Co-authored-by: ashn <60763262+ashn-dot-dev@users.noreply.github.com>
Co-authored-by: actondev (Christos) <chris.actondev@gmail.com>
Co-authored-by: vitopigno <103512727+VitusVeit@users.noreply.github.com>
Co-authored-by: Asdqwe <asdqwe@asdqwe.com>
Co-authored-by: Jeffery Myers <jeffm2501@gmail.com>
Co-authored-by: Ethan Simpson <ethansimpson@xtra.co.nz>
Co-authored-by: Nickolas McDonald <43690021+n77y@users.noreply.github.com>
Co-authored-by: Branimir Ričko <rickobranimir@gmail.com>
Co-authored-by: iacore <74560659+iacore@users.noreply.github.com>
Co-authored-by: Ethan Conneely <Econn50@outlook.com>
Co-authored-by: Johannes Barthelmes <615914+jbarthelmes@users.noreply.github.com>
Co-authored-by: bXi <bluepunk@gmail.com>
Co-authored-by: Ryan Roden-Corrent <ryan@rcorre.net>
Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com>
Co-authored-by: SuperUserNameMan <yoann@terminajones.com>
Co-authored-by: MichaelFiber <42419558+michaelfiber@users.noreply.github.com>
Co-authored-by: MichaelFiber <michael@cubeofb.org>
Co-authored-by: Dan Vu <danvu.hustle@gmail.com>
Co-authored-by: Gabriel dos Santos Sanches <gabrielssanches@gmail.com>
Co-authored-by: Rob Loach <robloach@gmail.com>
Co-authored-by: Peter0x44 <peter0x44@disroot.org>
Co-authored-by: Kenta <106167071+Its-Kenta@users.noreply.github.com>
Co-authored-by: bohonghuang <1281299809@qq.com>
Co-authored-by: turborium <45082001+turborium@users.noreply.github.com>
Co-authored-by: Wilson Silva <wilson.dsigns@gmail.com>
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.

[Text] (Web-based showcase) Emoji example "text_unicode" freezes up after enough emojis are clicked
1 participant