Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
May 04, 2017 Equivalent to nullptr | ||||
---|---|---|---|---|
| ||||
I was trying to use Derelict-SDL2 library, and the tutorial do this code below, as C++ code has nullptr word. How I use this? --------------------------------- struct Ball { SDL_Rect bbox = {0, 0, 100, 100}; SDL_Point vel = {1, 1}; } --------------------------------- case SDL_MOUSEBUTTONDOWN: { SDL_Point mousePos = {event.button.x, event.button.y}; if(event.button.button == SDL_BUTTON_LEFT && SDL_EnclosePoints(&mousePos, 1, &ball.bbox, nullptr) ) { SDL_Log("CLICK"); if(abs(ball.vel.x) < 32) { ball.vel.x *= 2; ball.vel.y *= 2; } } break; } |
May 04, 2017 Re: Equivalent to nullptr | ||||
---|---|---|---|---|
| ||||
Posted in reply to Leonardo | On Thursday, 4 May 2017 at 02:12:13 UTC, Leonardo wrote:
> nullptr word. How I use this?
Does it work if you just use `null` ?
|
May 04, 2017 Re: Equivalent to nullptr | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Thursday, 4 May 2017 at 02:45:30 UTC, Adam D. Ruppe wrote:
> On Thursday, 4 May 2017 at 02:12:13 UTC, Leonardo wrote:
>> nullptr word. How I use this?
>
> Does it work if you just use `null` ?
No.
First I got: source/app.d(45,69): Error: expression (*SDL_EnclosePoints)(& mousePos, 1, &ball.bbox, null) of type void does not have a boolean value
then I change to:
event.button.button == SDL_BUTTON_LEFT && SDL_TRUE == SDL_EnclosePoints(&mousePos, 1, &ball.bbox, null)
and got:
source/app.d(45,81): Error: void has no value
source/app.d(45,52): Error: incompatible types for ((SDL_TRUE) == ((*SDL_EnclosePoints)(& mousePos, 1, &ball.bbox, null))): 'int' and 'void'
|
May 04, 2017 Re: Equivalent to nullptr | ||||
---|---|---|---|---|
| ||||
Posted in reply to Leonardo | On Thursday, 4 May 2017 at 03:59:36 UTC, Leonardo wrote:
> On Thursday, 4 May 2017 at 02:45:30 UTC, Adam D. Ruppe wrote:
>> On Thursday, 4 May 2017 at 02:12:13 UTC, Leonardo wrote:
>>> nullptr word. How I use this?
>>
>> Does it work if you just use `null` ?
>
> No.
>
> First I got: source/app.d(45,69): Error: expression (*SDL_EnclosePoints)(& mousePos, 1, &ball.bbox, null) of type void does not have a boolean value
>
> then I change to:
> event.button.button == SDL_BUTTON_LEFT && SDL_TRUE == SDL_EnclosePoints(&mousePos, 1, &ball.bbox, null)
>
> and got:
> source/app.d(45,81): Error: void has no value
> source/app.d(45,52): Error: incompatible types for ((SDL_TRUE) == ((*SDL_EnclosePoints)(& mousePos, 1, &ball.bbox, null))): 'int' and 'void'
Ahh, looks to be a bug in DerelictSDL2. null will work for that last parameter, the problem is that the function should be returning an SDL_bool, but in Derelict it's declared as returning void: that's what the error message is saying.
I'll file a report, but with the conference underway, it may take a while to get fixed.
|
May 04, 2017 Re: Equivalent to nullptr | ||||
---|---|---|---|---|
| ||||
Posted in reply to Leonardo | In the meantime, you can get around the issue by redeclaring the function with another name and loading it manually just after calling DerelictSDL2.load():
>import derelict.sdl2.sdl;
>
>__gshared SDL_bool function (const(SDL_Point)*, int, const(SDL_Rect)*, SDL_Rect*) SDL_EnclosePoints_;
>
>void main()
>{
> DerelictSDL2.load();
> DerelictSDL2.bindFunc(cast(void**)&SDL_EnclosePoints_, "SDL_EnclosePoints");
> // ...
>}
Now you'd need to call SDL_EnclosePoints_ instead of SDL_EnclosePoints.
|
May 17, 2017 Re: Equivalent to nullptr | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stanislav Blinov | On Thursday, 4 May 2017 at 04:34:40 UTC, Stanislav Blinov wrote:
> In the meantime, you can get around the issue by redeclaring the function with another name and loading it manually just after calling DerelictSDL2.load():
>
>>import derelict.sdl2.sdl;
>>
>>__gshared SDL_bool function (const(SDL_Point)*, int, const(SDL_Rect)*, SDL_Rect*) SDL_EnclosePoints_;
>>
>>void main()
>>{
>> DerelictSDL2.load();
>> DerelictSDL2.bindFunc(cast(void**)&SDL_EnclosePoints_, "SDL_EnclosePoints");
>> // ...
>>}
>
> Now you'd need to call SDL_EnclosePoints_ instead of SDL_EnclosePoints.
Thank you.
|
Copyright © 1999-2021 by the D Language Foundation