Friday, November 27, 2020

Mystery crash in an SDL2 application (solved)

I am developing an application in SDL2. It works OK most of the time. But once in a while, it will crash while just going to refresh the screen with new content with SDL_RenderPresent(). The backtrace from gdb shows:

#0  0x00007ffff73a1c7b in raise () from /lib64/libc.so.6
#1  0x00007ffff7382548 in abort () from /lib64/libc.so.6       
#2  0x00007ffff35a682b in ?? () from /usr/lib64/xorg/modules/dri/iris_dri.so
#3  0x00007ffff40a5886 in ?? () from /usr/lib64/xorg/modules/dri/iris_dri.so
#4  0x00007ffff35c29e9 in ?? () from /usr/lib64/xorg/modules/dri/iris_dri.so
#5  0x00007ffff35b6d2b in ?? () from /usr/lib64/xorg/modules/dri/iris_dri.so
#6  0x00007ffff4ef99e0 in glPrimitiveBoundingBox () from /usr/lib64/libGLX_mesa.so.0
#7  0x00007ffff4eecad1 in ?? () from /usr/lib64/libGLX_mesa.so.0
#8  0x00007ffff7ef6283 in ?? () from /usr/lib64/libSDL2-2.0.so.0
#9  0x0000000000415f42 in refresh_display (ctx=0x7fffffffd370) at gui/main.c:1077
#10 0x0000000000413c79 in main_loop_handler (ctx=0x7fffffffd370) at gui/main.c:362
#11 0x0000000000413b22 in main (argc=1, argv=0x7fffffffdd58) at gui/main.c:323

I serached around the web with SDL2 crashing during SDL_RenderPresent(). Most of them points to some form of memory corruption causing that, but I have double check my code with various tools and manual inspection, there is no memory corruption. Then I came across this article "Rock solid frame rates with SDL2", it mentioned a function SDL_SetSwapInterval() which will delay SDL_RenderPresent() from swapping the render buffers till the swap interval (wait for vsync). This seems match what I suspected that the buffer is updated on the wrong time and causing the crash.

There is just a little problem, there is no more SDL_SetSwapInterval() any more, in stead it become SDL_GL_SetSwapInterval(). I added in the online call SDL_GL_SetSwapInterval(1), and vala, so far all test does not show the crash anymore.

Thursday, July 9, 2020

WebAssmebly passing string from C to JavaScript

Recently, I am working on a project that involves WebAssembly. In the project I would need to call out a JavaScript function with a C string char *string as parameter.

I could not get the string in JavaScript function, searching on the internet does not result in any useful information. None of the solutions I found are elegant. Then I realized I had used the WebSocket APIs from Emscripten, which is passing the URL as a C string to the underline JavaScript support function. How does it do that? I digged out the source of it and found in function emscripten_websocket_new, it is using UTF8ToString to convert the C string to a JavaScript String. UTF8ToString is Emscripten's runtime function, I could not call it directly from my JavaScript function.

According to the preamble.js document, I would need to use -s 'EXTRA_EXPORTED_RUNTIME_METHODS=["UTF8ToString"]' on the linker command to export the function and use it as Module.UTF8ToString. Problem solved.

Below are sample code that demonstrate the usage:
JavaScirpt function:

function processing_string_from_c(ptr, len) {
    var text = Module.UTF8ToString(ptr, len);
    ....
}
In the C code:
 char *string;
 ...
 EM_ASM({process_string_from_c($0, $1);}, string, strlen(string));
 ...
And in the linker line, remember to use
-s 'EXTRA_EXPORTED_RUNTIME_METHODS=["UTF8ToString"]'
P.S. In the latest release of emscripten, te export functions become global scope. So calls would be UTF8ToString() directly.

Wednesday, July 25, 2018

Slackware Creator Patrick Volkerding needs help

It was sad to know that Patrick (The creator/maintainer of Slackware) is on financial crisis.

It is unfortunate that he do not get his share of income from the store, and now he is

I mean, I'm sitting here in a house with a giant hole in the roof, a broken door sealed with duct tape, and a failed air conditioning condenser that I can't afford to fix, my wife has been driving on a spare tire for weeks, my teeth need serious attention again, and I only just got a machine here with UEFI for the first time (bought a used machine... really out of my budget but it had to be done).

The Slackware community is eager to help and for the time being Patrick gave his PayPal account link before he could setup a proper channel for donation.

Patrick Volkerding's Paypal account: https://www.paypal.me/volkerdi

And please donate if you like Slackware and willing to help.

Patrick has a cafepress account for Official Licensed Slackware Store. Confirmed by Patrick.

Friday, February 2, 2018

Why people think bitcoin has value, I still don't understand?

I still don't understand why people will value Bitcoin or any derivative coins.

When I first heard about the name of Bitcoin when it was first come out, my instinct think of it has absolutely no value besides wasting resources to calculate those blocks.

The so call decentralize nature of it only has value on the eyes criminal for money launching. Each and every transaction need to be kept in the bitcoin network and it is growing bigger and bigger. That is causing Transaction are getting longer and longer

Even with today's value of USD$8K per bitcoin, I still see no value of it.

Wednesday, October 4, 2017

New Ada for Slackware released

Finally, long after released of GNAT GPL 2017 and GCC in 7.x series in Slackware-current, I got some time to work on the Ada environment for Slackware and got a working version of GPS.

The new release is at GitHub

Friday, May 19, 2017