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

Cannot access all event attributes via sfRenderWindow_pollEvent #2

Closed
efrizoid opened this issue Jul 23, 2019 · 6 comments
Closed

Cannot access all event attributes via sfRenderWindow_pollEvent #2

efrizoid opened this issue Jul 23, 2019 · 6 comments

Comments

@efrizoid
Copy link

sfRenderWindow_pollEvent function works only with sfEvent type. How can I access event attributes other than event type (like mouse position or pressed key code) when using this function? These attributes are declared in other types like e.g. sfMouseButtonEvent and it looks to me that these are not accessible via sfRenderWindow_pollEvent function.

If I understand correctly, in CSFML sfEvent type should be union of more concrete event types like sfKeyEvent.

@Gnimuc
Copy link
Member

Gnimuc commented Jul 23, 2019

Since there is no one-to-one correspondence between Julia struct and C union, you need to use pointer arithmetic or some packages like Blobs.jl.

@Gnimuc
Copy link
Member

Gnimuc commented Jul 23, 2019

reinterpret might also work.

@efrizoid
Copy link
Author

Ok, thanks for the tips. I'm still wondering though... When julia creates sfEvent object it only allocates memory for the type attribute and C function gets only a pointer to that object. It then seems that C function could write to memory which does not belong to that sfEvent object when trying to manipulate other attributes which sfEvent union is assumed to have. Couldn't this lead to memory corruption or segfaults?

@Gnimuc
Copy link
Member

Gnimuc commented Jul 26, 2019

Good question. I guess this might due to an old bug in Clang.jl, now it generates:

struct sfEvent
    key::sfKeyEvent
end

which is the largest field in the union. However, it is quite annoying for end-users when querying data from such a union. I'm going to overload getproperty to mimic the C union behavior, so users don't need to do pointer arithmetics.

@Gnimuc Gnimuc closed this as completed in 863e660 Jul 26, 2019
@Gnimuc
Copy link
Member

Gnimuc commented Jul 26, 2019

Hi @EimantasLedinauskas, it should work now, you could give the example in the master branch a try. BTW, would you like me to tag a new release for this change?

My current plan is to wait CEnum.jl's overhaul which will break everything that depends on it and then I'll regenerate the whole C bindings using Clang.jl. But if you're urgent, I'll tag the new release tomorrow.

@efrizoid
Copy link
Author

Nice, thanks! It's not urgent, I can wait for the planned release :)

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

No branches or pull requests

2 participants