Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

Calling a function from member inside array in another array

$
0
0

I was creating a custom operating system and I have a problem. I have an array of child components in an array of all opened windows. When I call a function CDraw (Component Draw) on the child array the system crashes with the message "General Protection Fault Detected".

Window array and code:

int openedWindows = 0;Window* windows[128];int OpenWindow(Window win) {    windows[0][openedWindows] = win;    openedWindows++;    return openedWindows-1;};void CloseWindow(int index) {    for(int i = index+1; i < 127; i++) {        if(i != 127)            windows[0][i] = windows[0][i-1];        else            windows[0][i] = Window();    }    openedWindows--;};void CloseAllWindows() {    for(int i = 0; i < 127; i++) {        windows[0][i] = Window();    }    openedWindows = 0;};/*Draw Windows*/for(int i = 0; i < openedWindows; i++){    windows[0][i].Update();}

Where I call the code:

Window wnd = Window("Window");wnd.Update();Button btn = Button(wnd, "Hello");btn.CPosition = Point(10, 10);btn.BackColor = Color(MediumTurquoise);btn.parent = &wnd;btn.parent->AddComponent(btn);btn.Update();Button btn2 = Button(wnd, "H2");btn2.CPosition = Point(100, 100);btn2.BackColor = Color(Red);btn2.parent = &wnd;btn2.parent->AddComponent(btn2);btn2.Update();  OpenWindow(wnd);

Componet code:

int childIndex = 0;BaseGuiComponent* children[128];int BaseGuiComponent::AddComponent(BaseGuiComponent baseGuiComponent) {    children[0][childIndex] = baseGuiComponent;    childIndex++;    return childIndex-1;};void BaseGuiComponent::RemoveComponent(int index) {    for(int i = index+1; i < 127; i++) {        if(i != 127)            children[0][i] = children[0][i-1];        else            children[0][i] = BaseGuiComponent();    }    childIndex--;};void BaseGuiComponent::ClearComponents() {    for(int i = 0; i < 127; i++) {        children[0][i] = BaseGuiComponent();    }    childIndex = 0;};//List components and Update();void BaseGuiComponent::DrawChildren() {    for(int i = 0; i < childIndex; i++) {        children[0][i].Update();    }};

Drawing code:

void BaseGuiComponent::CDraw() {    if (strcmp(type,"Window",128)) {        Draw->DrawWindow(BackColor.GetHexColor(), CPosition.X, CPosition.Y, CSize.Width, CSize.Height, 2, CText, WindowStyle, Draw->GetScreenBounds());        DrawChildren();    } else if (strcmp(type,"Button",128)) {        Draw->FillRect(BackColor.GetHexColor(), CGlobalPosition.X*4, CGlobalPosition.Y, CSize.Width*4, CSize.Height, parent->bound/* Conflicting code */);        Draw->PRINTAT(ForeColor.GetHexColor(),CText, CGlobalPosition.X + nabs(CSize.Width - svlen(CText))/2,CGlobalPosition.Y + nabs(CSize.Height-16)/2, bound);    }};

All help is welcomed. Thanks.


Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>