Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

error in sdl native #837

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

error in sdl native #837

wants to merge 6 commits into from

Conversation

zwykl3
Copy link

@zwykl3 zwykl3 commented May 11, 2019

cc main.c -std=c99 -pedantic -O2 -o main -lSDL2 -lm
In file included from main.c:22:
./nuklear_sdl.h:63:9: error: void function 'nk_sdl_font_create_from_file' should not return a value [-Wreturn-type]
return NULL;
^ ~~~~
./nuklear_sdl.h:198:35: warning: incompatible pointer types passing 'const float *' to parameter of type 'const Sint16 *'
(aka 'const short ') [-Wincompatible-pointer-types]
sdl_draw_polyline((const float
)&vertices, (2 * sizeof(float)),(int)p->point_count, p->color);
^~~~~~~~~~~~~~~~~~~~~~~
./nuklear_sdl.h:124:38: note: passing argument to parameter 'vx' here
void sdl_draw_polyline(const Sint16 *vx, const Sint16 *vy, int n, struct nk_color color) {
^
./nuklear_sdl.h:198:60: warning: incompatible integer to pointer conversion passing 'unsigned long' to parameter of type 'const Sint16 *'
(aka 'const short ') [-Wint-conversion]
sdl_draw_polyline((const float
)&vertices, (2 * sizeof(float)),(int)p->point_count, p->color);
^~~~~~~~~~~~~~~~~~~
./nuklear_sdl.h:124:56: note: passing argument to parameter 'vy' here
void sdl_draw_polyline(const Sint16 *vx, const Sint16 *vy, int n, struct nk_color color) {
^
./nuklear_sdl.h:209:41: warning: incompatible pointer types passing 'const float *' to parameter of type 'const Sint16 '
(aka 'const short ') [-Wincompatible-pointer-types]
sdl_draw_filled_polygon((const float
)&verticesx, (const float
)&verticesy,
^~~~~~~~~~~~~~~~~~~~~~~~
./nuklear_sdl.h:132:44: note: passing argument to parameter 'vx' here
void sdl_draw_filled_polygon(const Sint16 *vx, const Sint16 *vy, int n, struct nk_color color) {
^
./nuklear_sdl.h:209:67: warning: incompatible pointer types passing 'const float *' to parameter of type 'const Sint16 '
(aka 'const short ') [-Wincompatible-pointer-types]
sdl_draw_filled_polygon((const float
)&verticesx, (const float
)&verticesy,
^~~~~~~~~~~~~~~~~~~~~~~~
./nuklear_sdl.h:132:62: note: passing argument to parameter 'vy' here
void sdl_draw_filled_polygon(const Sint16 *vx, const Sint16 *vy, int n, struct nk_color color) {
^
./nuklear_sdl.h:226:32: warning: passing 'const struct nk_image *' to parameter of type 'struct nk_image *' discards qualifiers
[-Wincompatible-pointer-types-discards-qualifiers]
sdl_draw_image(&i->img, i->x, i->y, i->w, i->h);
^~~~~~~
./nuklear_sdl.h:136:38: note: passing argument to parameter 'img' here
void sdl_draw_image(struct nk_image *img, int x, int y, int w, int h) {
^
./nuklear_sdl.h:280:26: warning: incompatible pointer types initializing 'struct nk_user_font *' with an expression of type
'struct nk_user_font **'; remove & [-Wincompatible-pointer-types]
struct nk_user_font *font = &sdl.user_font;
^ ~~~~~~~~~~~~~~
6 warnings and 1 error generated.
make: *** [main] Error 1

@zwykl3
Copy link
Author

zwykl3 commented Jun 10, 2019

I still get this same error

cc main.c -std=c99 -Wall -pedantic -O0 -o main -lSDL2 -lSDL2_ttf -lSDL2_gfx -lm
In file included from main.c:22:
./nuklear_sdl.h:63:9: error: void function 'nk_sdl_font_create_from_file' should not return a value
      [-Wreturn-type]
        return NULL;
        ^      ~~~~

@zwykl3
Copy link
Author

zwykl3 commented Jun 10, 2019

When I would change background i get secmentation 11

Copy link
Contributor

@dumblob dumblob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your effort - I'm glad we'll finally have a "pure" SDL backend in the repo. Just to maintain the absolute minimal code quality, please take a look at the comments.

One more question - why did you add a submodule (Submodule nuklear added at 576ab0) in this pull? There shouldn't be any need for that.

sdl.ttf_font = TTF_OpenFont(file_name, font_size);
if (sdl.ttf_font == NULL) {
fprintf(stdout, "Unable to load font file: %s\n", file_name);
return NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return NULL; -> return; as it's a void function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad we'll finally have a "pure" SDL backend in the repo.
In main repo noexist SDL2 native

Your code working? Please change the background color in demo program

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether I understand you correctly. Which background color on which line in the source code in which demo program and why?

TTF_Font *ttf_font;
struct nk_user_font *user_font;
int font_height;
} sdl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to merge this commit, but because we prefer thread safe code, we should avoid global variables. Do you want to change the APIs to accept struct nk_sdl as argument? If not, I might accept it with global variable to have at least something in the repo.

as nuklear uses variable size buffers and al_get_text_width doesn't
accept a length, it infers length from null-termination
(which is unsafe API design by allegro devs!) */
char strcpy[len+1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use variable names conflicting with C standard library names (see man strcpy).

nk_input_key(ctx, NK_KEY_TEXT_WORD_RIGHT, down);
else nk_input_key(ctx, NK_KEY_RIGHT, down);
} else return 0;
return 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this return? Or alternatively the purpose of the return on the previous line?

@dumblob dumblob mentioned this pull request Jul 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants