• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Getting a Segmentation fault for some reason when im not doing anything with memory

nomacaly

New Coder
first time posting here. hello.
i have run into a strange issue when creating my pixel graphics engine,

for some strange reason I'm getting a Segmentation fault when i comment out drawFilledRect, and try to draw a character.

C:
//Gives me a Segmentation fault (core dumped)
void draw()
{
  Color green = {0,255,0};
  Color blue  = {0,0,255};
  Color red = {255,0,0};
  Color something = {40,10,30};
 
  Vector2 pos = {0,0};
  Vector2 dim = {25,25};
 
  //drawFilledRect(pos, dim, red);
  drawCharacter(65,20,0,green);
}

but when its not commented out it works? what.
Code:
void draw()
{
  Color green = {0,255,0};
  Color blue  = {0,0,255};
  Color red = {255,0,0};
  Color something = {40,10,30};
 
  Vector2 pos = {0,0};
  Vector2 dim = {25,25};
 
  drawFilledRect(pos, dim, red);
  drawCharacter(65,20,0,green);
}

image of what i should be getting: renderer




i don't know if i am explaining this correctly since i don't even know why this is happening.
 
drawCharacter(65,20,0,green);
here's the code thats inside the drawCharacter function
void drawCharacter(int chr, int x, int y, Color c)
{
int cy;

for(int i=0; i <8; i++)
{
for(int j=0; j <8; j++)
{
if (font[chr][cy] & (1<<i))
{
drawPixel(x+i,y-j+8,c);
}
cy++;
}
cy =0;
}
}
i have a really strong feeling that this
C:
if (font[chr][cy] & (1<<i))
is whats causing me a pain but i need it or the character wont be rendered correctly
 
Top Bottom