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

Commit

Permalink
Fix bbutil render_text indices (saves memory).
Browse files Browse the repository at this point in the history
  • Loading branch information
mlepage authored and Anthony Hu committed Jul 12, 2012
1 parent d480c64 commit acdd479
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CubeRotate/bbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
int i, c;
GLfloat *vertices;
GLfloat *texture_coords;
GLshort* indices;
GLushort* indices;

float pen_x = 0.0f;

Expand All @@ -505,7 +505,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
vertices = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
texture_coords = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);

indices = (GLshort*) malloc(sizeof(GLfloat) * 6 * msg_len);
indices = (GLushort*) malloc(sizeof(GLushort) * 6 * msg_len);

for(i = 0; i < msg_len; ++i) {
c = msg[i];
Expand Down
4 changes: 2 additions & 2 deletions FallingBlocks/bbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
int i, c;
GLfloat *vertices;
GLfloat *texture_coords;
GLshort* indices;
GLushort* indices;

float pen_x = 0.0f;

Expand All @@ -505,7 +505,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
vertices = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
texture_coords = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);

indices = (GLshort*) malloc(sizeof(GLfloat) * 6 * msg_len);
indices = (GLushort*) malloc(sizeof(GLushort) * 6 * msg_len);

for(i = 0; i < msg_len; ++i) {
c = msg[i];
Expand Down
4 changes: 2 additions & 2 deletions GLES11Template/bbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
int i, c;
GLfloat *vertices;
GLfloat *texture_coords;
GLshort* indices;
GLushort* indices;

float pen_x = 0.0f;

Expand All @@ -505,7 +505,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
vertices = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
texture_coords = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);

indices = (GLshort*) malloc(sizeof(GLfloat) * 6 * msg_len);
indices = (GLushort*) malloc(sizeof(GLushort) * 6 * msg_len);

for(i = 0; i < msg_len; ++i) {
c = msg[i];
Expand Down
4 changes: 2 additions & 2 deletions GLES20Template/bbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
int i, c;
GLfloat *vertices;
GLfloat *texture_coords;
GLshort* indices;
GLushort* indices;

float pen_x = 0.0f;

Expand All @@ -505,7 +505,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
vertices = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
texture_coords = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);

indices = (GLshort*) malloc(sizeof(GLfloat) * 6 * msg_len);
indices = (GLushort*) malloc(sizeof(GLushort) * 6 * msg_len);

for(i = 0; i < msg_len; ++i) {
c = msg[i];
Expand Down
4 changes: 2 additions & 2 deletions GoodCitizen/bbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
int i, c;
GLfloat *vertices;
GLfloat *texture_coords;
GLshort* indices;
GLushort* indices;

float pen_x = 0.0f;

Expand All @@ -505,7 +505,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
vertices = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
texture_coords = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);

indices = (GLshort*) malloc(sizeof(GLfloat) * 6 * msg_len);
indices = (GLushort*) malloc(sizeof(GLushort) * 6 * msg_len);

for(i = 0; i < msg_len; ++i) {
c = msg[i];
Expand Down
4 changes: 2 additions & 2 deletions HelloWorldDisplay/bbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
int i, c;
GLfloat *vertices;
GLfloat *texture_coords;
GLshort* indices;
GLushort* indices;

float pen_x = 0.0f;

Expand All @@ -505,7 +505,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
vertices = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
texture_coords = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);

indices = (GLshort*) malloc(sizeof(GLfloat) * 6 * msg_len);
indices = (GLushort*) malloc(sizeof(GLushort) * 6 * msg_len);

for(i = 0; i < msg_len; ++i) {
c = msg[i];
Expand Down
4 changes: 2 additions & 2 deletions Keyboard/bbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
int i, c;
GLfloat *vertices;
GLfloat *texture_coords;
GLshort* indices;
GLushort* indices;

float pen_x = 0.0f;

Expand All @@ -505,7 +505,7 @@ void bbutil_render_text(font_t* font, const char* msg, float x, float y, float r
vertices = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);
texture_coords = (GLfloat*) malloc(sizeof(GLfloat) * 8 * msg_len);

indices = (GLshort*) malloc(sizeof(GLfloat) * 6 * msg_len);
indices = (GLushort*) malloc(sizeof(GLushort) * 6 * msg_len);

for(i = 0; i < msg_len; ++i) {
c = msg[i];
Expand Down

9 comments on commit acdd479

@pelegri
Copy link
Contributor

Choose a reason for hiding this comment

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

Marc, is this patch only applicable to BB10 or also to PlayBook? Even if we were to only apply it to the BB10 b/c of testing/resourcing, it might be useful to document it accordingly.

@rsperanza
Copy link
Member

@rsperanza rsperanza commented on acdd479 Jul 25, 2012 via email

Choose a reason for hiding this comment

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

@mlepage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Eduardo, it is applicable to any and all code that has those lines. When malloc'ing the array of shorts, the size should be a multiple of shorts (2 bytes) not floats (4 bytes). The two types must match in the malloc. Additionally, since this is for OpenGL, it should be unsigned short not signed short. They're the same size, but later when it's used with OpenGL, the flag passed is for unsigned short, since signed short is not a legal option. Other places in the code correctly use unsigned short in this case, but this one didn't.

@mlepage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the future, ideally there would be a solution for not duplicating these lines (files) in every sample. That will keep them limited to one place in github, instead of half a dozen. Maybe a library.

@jhoffmannrim
Copy link
Contributor

Choose a reason for hiding this comment

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

This commit has been merged into develop branch (for BB10) with Pull Request #28.

The reason that the code is duplicated in each sample is so that each sample is standalone. The samples are for developers new to the platform and we don't want to complicate the build process by creating a library that they have to get working before they can use the samples.

@mlepage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, good to finally see this fix go in, thanks!

For code sharing, I was thinking along the lines of having the individual samples reference a common file in a sibling directory. So each builds in the file (no lib) but it's in one place. There's probably a way to have git deal with this using links of some sort.

@mlepage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I see it's still just in develop. At what point will the incorrect master code be fixed? This should be a hotfix to the incorrect code in the current release, it shouldn't be waiting for a new release.

@anhu
Copy link

@anhu anhu commented on acdd479 Jul 27, 2012 via email

Choose a reason for hiding this comment

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

@mlepage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thanks Anthony!

Please sign in to comment.