Page 1 of 1
Can't read from objects of sub-class of ItemEntry?
Posted: Mon Mar 16, 2009 03:34
by yllfever
Hi, every one.
Here is another problem i have.
I tried to use the getBuddyId() method below, and get a crash.
"... Access violation reading location 0xfeeefef2. "
Why ?
Code: Select all
#pragma once
#include <cegui/CEGUI.h>
namespace CEGUI {
class ImageListboxItem : public CEGUI::ItemEntry
{
protected:
String buddyId;
public:
static const String WidgetTypeName;
ImageListboxItem(const String &type, const String &name);
~ImageListboxItem();
String getBuddyId(){ return buddyId; };
void setBuddyId(const CEGUI::String& newBuddyId){
buddyId = newBuddyId;
}
};
CEGUI_DECLARE_WINDOW_FACTORY(ImageListboxItem)
};
Posted: Mon Mar 16, 2009 14:28
by CrazyEddie
Hi, and welcome
Debug callstack, pls
CE.
Posted: Tue Mar 17, 2009 03:16
by yllfever
Hi, thanks for you reply.
I tried the issue again, and gain a "bad allocation" this time.
This is my derived class:
Code: Select all
namespace CEGUI
{
class CheckListboxItem : public ItemEntry
{
protected:
String a;
public:
String getA() {
return a;
}
void setA(const String& newA)
{
a = newA;
}
CheckListboxItem(const String &type, const String &name);
virtual ~CheckListboxItem();
static const String WidgetTypeName;
};
CEGUI_DECLARE_WINDOW_FACTORY(CheckListboxItem)
}
And in my "looknfeel":
Code: Select all
<WidgetLook name="TaharezLook/ImageListboxItem">
<PropertyDefinition name="TextColour" initialValue="FFFFFFFF" redrawOnWrite="true" />
<PropertyDefinition name="SelectedTextColour" initialValue="FF7c7c7c" redrawOnWrite="true" />
<PropertyDefinition name="SelectionBrush" initialValue="set:TaharezLook image:Background" redrawOnWrite="true" />
<PropertyDefinition name="SelectionColour" initialValue="003030FF" redrawOnWrite="true" />
<PropertyDefinition name="IconImage" initialValue="" redrawOnWrite="true" />
<PropertyDefinition name="UserId" initialValue="" redrawOnWrite="false" />
<Property name="Selectable" value="True" />
<NamedArea name="ContentSize">
<Area>
<Dim type="LeftEdge" >
<AbsoluteDim value="0" />
</Dim>
<Dim type="TopEdge" >
<AbsoluteDim value="0" />
</Dim>
<Dim type="Width" >
<FontDim type="HorzExtent" padding="6" />
</Dim>
<Dim type="Height" >
<FontDim type="LineSpacing" />
</Dim>
</Area>
</NamedArea>
<ImagerySection name="myicon">
<ImageryComponent>
<Area>
<Dim type="TopEdge">
<AbsoluteDim value="0" />
</Dim>
<Dim type="LeftEdge">
<AbsoluteDim value="0" />
</Dim>
<Dim type="RightEdge">
<UnifiedDim scale="1" type="Height" />
</Dim>
<Dim type="BottomEdge">
<UnifiedDim scale="1" type="Height" />
</Dim>
</Area>
<ImageProperty name="IconImage" />
<VertFormat type="Stretched" />
<HorzFormat type="Stretched" />
</ImageryComponent>
</ImagerySection>
<ImagerySection name="label">
<TextComponent>
<Area>
<Dim type="TopEdge">
<AbsoluteDim value="0" />
</Dim>
<Dim type="LeftEdge">
<AbsoluteDim value="18" />
</Dim>
<Dim type="RightEdge">
<UnifiedDim scale="1" offset="-3" type="RightEdge" />
</Dim>
<Dim type="BottomEdge">
<UnifiedDim scale="1" type="BottomEdge" />
</Dim>
</Area>
</TextComponent>
</ImagerySection>
<ImagerySection name="selection">
<ImageryComponent>
<Area>
<Dim type="TopEdge">
<AbsoluteDim value="0" />
</Dim>
<Dim type="LeftEdge">
<UnifiedDim scale="1" type="Height" />
</Dim>
<Dim type="RightEdge">
<UnifiedDim scale="1" type="RightEdge" />
</Dim>
<Dim type="BottomEdge">
<UnifiedDim scale="1" type="BottomEdge" />
</Dim>
</Area>
<ImageProperty name="SelectionBrush" />
<ColourProperty name="SelectionColour" />
<VertFormat type="Stretched" />
<HorzFormat type="Stretched" />
</ImageryComponent>
</ImagerySection>
<StateImagery name="Enabled">
<Layer>
<Section section="label">
<ColourProperty name="TextColour" />
</Section>
<Section section="myicon">
</Section>
</Layer>
</StateImagery>
<StateImagery name="Disabled">
<Layer>
<Section section="label">
<ColourProperty name="TextColour" />
</Section>
<Section section="myicon">
</Section>
</Layer>
</StateImagery>
<StateImagery name="SelectedEnabled">
<Layer>
<Section section="selection" />
<Section section="label">
<ColourProperty name="SelectedTextColour" />
</Section>
<Section section="myicon">
</Section>
</Layer>
</StateImagery>
<StateImagery name="SelectedDisabled">
<Layer>
<Section section="selection" />
<Section section="label">
<ColourProperty name="SelectedTextColour" />
</Section>
<Section section="myicon">
</Section>
</Layer>
</StateImagery>
</WidgetLook>
Posted: Tue Mar 17, 2009 03:23
by yllfever
My layout file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<GUILayout>
<Window Type="TaharezLook/FrameWindow" Name="MainWindow" >
<Property Name="UnifiedAreaRect" Value="{{0.15,0},{0.15,0},{0.85,0.00},{0.85,0.0}}" />
<Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
<Window Type="TaharezLook/Button" Name="TestButton">
<Property Name="UnifiedAreaRect" Value="{{0.03,0},{0.45, 0},{0.12, 0},{0.55, 0}}" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="Text" Value="LDK" />
</Window>
<Window Type="TaharezLook/ItemListbox" Name="MainWindow/ItemList">
<Property Name="UnifiedAreaRect" Value="{{0.15,0},{0.15,0},{0.85,0.00},{0.85,0.0}}" />
<Property Name="UnifiedMaxSize" Value="{{1.000000,0.000000},{1.000000,0.000000}}" />
</Window>
</Window>
</GUILayout>
In my main.cpp :
Code: Select all
namespace CEGUI {
void bindCEGUI()
{
CEGUI::WindowFactoryManager& wfMgr = CEGUI::WindowFactoryManager::getSingleton();
wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(CheckListboxItem));
wfMgr.addFalagardWindowMapping("WindowsLook/CheckListboxItem", "CEGUI/ItemEntry", "WindowsLook/CheckListboxItem", "Falagard/ItemEntry");
wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(ImageListboxItem));
wfMgr.addFalagardWindowMapping("TaharezLook/ImageListboxItem", "CEGUI/ItemEntry", "TaharezLook/ImageListboxItem", "Falagard/ItemEntry");
}
}
bool MyDemo2Sample::initialiseSample()
{
...
CEGUI::CheckListboxItem* testItem = static_cast<CheckListboxItem*>(winMgr.createWindow(looknfeel + "/ImageListboxItem", "test"));
testItem->setText("Helo");
testItem->setProperty("IconImage", "set:eachigo image:ImageSmileNormal");
std::cout << testItem->getA() << std::endl; //<==Where The "bad allocation" I got.
...
}The callstack:
Code: Select all
> MyDemo2.exe!CEGUI::CheckListboxItem::getA() Line 14 C++
MyDemo2.exe!MyDemo2Sample::initialiseSample() Line 66 + 0x12 C++
CEGUISampleHelper_d.dll!CEGuiD3D9BaseApplication::execute(CEGuiSample * sampleApp=0x0012ff48) Line 158 + 0xd C++
CEGUISampleHelper_d.dll!CEGuiSample::initialise() Line 241 + 0x19 C++
CEGUISampleHelper_d.dll!CEGuiSample::run() Line 122 + 0xd C++
MyDemo2.exe!main(int argc=1, char * * argv=0x01060da8) Line 26 + 0xb C++
MyDemo2.exe!mainCRTStartup() Line 398 + 0x11 C
kernel32.dll!7c817067()
Thanks again.
Posted: Tue Mar 17, 2009 03:27
by yllfever
Becouse of the problem.
I had to define some properties in my looknfeel, and use setProperty(),
and getProperty() .
Is it possible for me to add "property" in my derived class ?
Posted: Tue Mar 17, 2009 11:40
by CrazyEddie
While you declare the window factory, I do not see where it's defined, fx:
Code: Select all
CEGUI_DEFINE_WINDOW_FACTORY( ImageListboxItem )
You can add properties in your classes. Properties are derived from CEGUI::Property and you override the get/set member funcs. Usually you then declare the property as a static member of your Window subclass, and call addProperty( &myProperty ); in the constructor.
You might also want to took at 'user strings' which is effectively a per-window instance dictionary of String keys and values (and is how looknfeel defined properties are implemented internally).
See:
Window::setUserString and
Window::getUserString.
CE.