The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
RenderCopy and RenderCopyEx SIGSEGV with FreePascal
Anyeos


Joined: 03 Apr 2014
Posts: 1
I am using FPC to develop a game and it end with SIGSEGV when try to call SDL_RenderCopy or SDL_RenderCopyEx.
I debbuged it and the debugger stoped just in the assignment of real_srcrect and real_dstrect.

It appears that Pascal don't "like" that kind of things. As a solution I commented the assignment and it worked as expected.

Considering it is not neccesary to assign a value to that two vars. So, it will not hurt or damage anything (I checked the code).

The Pascal working code of the function is as follow:

Code:
int
SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
{
    SDL_Rect real_srcrect;// = { 0, 0, 0, 0 }; // This raise SIGSEGV in Free Pascal binary programs
    SDL_Rect real_dstrect;// = { 0, 0, 0, 0 }; // This raise SIGSEGV in Free Pascal binary programs
    SDL_FRect frect;

    CHECK_RENDERER_MAGIC(renderer, -1);
    CHECK_TEXTURE_MAGIC(texture, -1);

    if (renderer != texture->renderer) {
        return SDL_SetError("Texture was not created with this renderer");
    }

    real_srcrect.x = 0;
    real_srcrect.y = 0;
    real_srcrect.w = texture->w;
    real_srcrect.h = texture->h;
    if (srcrect) {
        if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
            return 0;
        }
    }

    SDL_RenderGetViewport(renderer, &real_dstrect);
    real_dstrect.x = 0;
    real_dstrect.y = 0;
    if (dstrect) {
        if (!SDL_HasIntersection(dstrect, &real_dstrect)) {
            return 0;
        }
        real_dstrect = *dstrect;
    }

    if (texture->native) {
        texture = texture->native;
    }

    /* Don't draw while we're hidden */
    if (renderer->hidden) {
        return 0;
    }

    frect.x = real_dstrect.x * renderer->scale.x;
    frect.y = real_dstrect.y * renderer->scale.y;
    frect.w = real_dstrect.w * renderer->scale.x;
    frect.h = real_dstrect.h * renderer->scale.y;

    return renderer->RenderCopy(renderer, texture, &real_srcrect, &frect);
}


Can that "solution" be included in the official SDL?
Don't forget that there are just two functions affected: SDL_RenderCopy and SDL_RenderCopyEx.

Considerations:
It is not some bad SDL Pascal header declaration. I checked all that carefully.
It is not something bad in my code that possibly generates memory leaks. It raise SIGSEGV in the simplest and basic example of SDL2 too.
The debugger stops exactly in that lines, and If I declare the var in a place and assign the value in another place, it raise the SIGSEGV exactly in the assignment place.

It maybe related as how Pascal works with that kind of types, maybe Pascal uses something more to know before assign a value as is. As I know, in Pascal you must explicitly specify the type before assigning a value (if it is something like a generic pointer).
So maybe Pascal is missunderstanding the type class (or it is not possible to tell that to Pascal) or is a bug in Pascal itself.

Whaterver this solves that problem with Pascal for now.


Thank you guys for your great work with SDL2.

PS: If I need to file a bug please tell me how. But if you can file it for me I will be thankful because I have a lot of work to do and don't have the time (I just take part of my time to write this).

Bye bye