I'm attempting to do a simple test to create and populate a List inside of a window. The goal here is to create an Inventory GUI that functions similar to the SkyUI mod for Skyrim.
Everything seems to work except for the part where I actually try to populate the darn thing with some dummy test data. It builds fine, but the game crashes whenever I call the setData method, passing a Memx object to it.
This is basically my code here:
Code:
void InventoryWindow::Create()
{
Text_ds.color = BLACK;
Text_ds.shadow = 0;
Gui += window.create(Rect(-0.5f, -0.4f, 0.5f, 0.4f), "Inventory");
window += region.create(Rect( 0.05f, -0.6f, 0.95f, -0.1f));
window.hide();
IsShowing = false;
}
void InventoryWindow::Show()
{
if (!IsShowing)
{
invItems.clear();
Memx<ItemInfo> data;
ItemInfo &itemInfo = data.New();
itemInfo.name = "Test 1";
itemInfo.damage = 20;
itemInfo.value = 5;
ListColumn list_column[]=
{
ListColumn(MEMBER(ItemInfo, name), 0.3f, L"Name"),
ListColumn(MEMBER(ItemInfo, damage), 0.3f, L"Damage"),
ListColumn(MEMBER(ItemInfo, value), 0.3f, L"Value")
};
region += invItems.create(list_column, Elms(list_column)).setData(data);
Ms.visible(true);
window.show();
IsShowing = true;
}
}
I'm ultimately calling the above InventoryWindow.Show() method using an Input handling class that I created that "listens" for input in the UpdateGame() function in Game.cpp.
ItemInfo is just a struct I created with 3 basic properties for testing. I noticed that if I remove the ItemInfo &itemInfo = data.New(); part OR if I remove the setData(data) lines, the crash doesn't occur (I just get a blank grid with some column headers). I've peeled through the tutorials, the documentation, I've read every thread in this forum dealing with Memx and List. I've been through the RPG2 source code, trying every alternative I can think of to try and get this to work and I'm just not sure what I'm doing wrong here. I've also tried this same approach using the other Mem type classes and even using a simple, regular old array of my ItemInfo struct. I get the same result for all the variations.
Admittedly, C++ (particularly working with pointers) isn't my strong suit as I've been working professionally with C# for quite awhile now, haven't really had to work much with C++, and so I may be doing something wrong in regards to some required pointer manipulation (yes I know I'm not using a pointer in the above example, but I've tried passing a pointer to data instead of data itself during all of this). If someone could just glance at the above code and give me some suggestions as to what I may be doing wrong, it would be greatly appreciated.