I am making a MFC like class build on the WinAPI as an exersise.
Now am i running into the problem that i am getting a runtime error while i execute the code.
In My Main the following lines are present:
void MyApp::Init(int nCmd)
{
main.Create(L"This is the MainFrame Window");
main.ActivateFrame(nCmd);
GWnd* p= main.GetActiveView();//Get pointer to the first view of the FrameWnd
//p->GetID();
}
The commented out line causes the error.
The GWnd class constructors:
//Standard classname
GWnd::GWnd() :m_ClassName(L"Wnd"), BaseWnd(), m_pOwnerWnd(NULL)
{
GWnd::Init();
}
//Userdefined Classname
GWnd::GWnd(LPCWSTR ClassName) : m_ClassName(ClassName), BaseWnd(), m_pOwnerWnd(NULL)
{
GWnd::Init();
}
//Copy constructor
GWnd::GWnd(const GWnd& Wnd) : BaseWnd(GetHwnd()), m_pOwnerWnd(NULL)
{
m_ClassName = L"Wnd";
}
The assignment function:
//Operators
operator HWND() { return BaseWnd<GWnd>::GetHwnd(); }
GWnd operator=(GWnd Wnd)
{
GWnd tmp(Wnd);
}
I hope the lines of code are sufficient for your answers. Does someone understands the issue i am running into? And could give me a hint where to look further?
try to add this:
GWnd* p= (GWnd*)main.GetActiveView();
instead of this:
GWnd* p= main.GetActiveView();
and then use this
p->GetDlgCtrlID()
Related
I am trying to use TLM2 for a simulation project but for some reason I can't use b_transport the same way I see it used in other projects, here is the code snippet that doesn't build due to this error(error C2039 : 'b_transport' : is not a member of 'tlm_utils::simple_initiator_socket<Initiator,32,tlm::tlm_base_protocol_types>')
#include <systemc.h>
#include <tlm_utils/simple_target_socket.h>
#include <tlm_utils/simple_initiator_socket.h>
SC_MODULE(Memory) {
tlm_utils::simple_target_socket<Memory> targetSocket;
SC_CTOR(Memory) {
targetSocket.register_b_transport(this, &BTransportCallback);
}
void BTransportCallback(tlm::tlm_generic_payload& payload, sc_time& delay) {
// ...
}
};
SC_MODULE(Initiator) {
tlm_utils::simple_initiator_socket<Initiator> initiatorSocket;
SC_CTOR(Initiator) {
}
};
SC_MODULE(TopLevel) {
Memory* memory;
Initiator* initiator;
SC_CTOR(TopLevel) {
memory = new Memory("Memory");
initiator = new Initiator("Initiator");
initiator->initiatorSocket.bind(memory->targetSocket);
// this is just an example for build test, obviously this isn't a correct call
tlm::tlm_generic_payload p;
initiator->initiatorSocket.b_transport(p, SC_ZERO);
}
};
I know what this error implies, but I don't understand why the systemc includes with tlm2 doesn't find this method.
I use SystemC 2.3.3 (Includes TLM), and there are no issues at includes, since I can use other systemc things normally.
Please let me know if you encountered something similar or what I might've overlooked(maybe I am using the wrong headers ?).
I found the issue. I had to use the arrow (->) operator, so this is the correct usage
SC_MODULE(TopLevel) {
Memory* memory;
Initiator* initiator;
SC_CTOR(TopLevel) {
memory = new Memory("Memory");
initiator = new Initiator("Initiator");
sc_time delay = SC_ZERO_TIME;
tlm::tlm_generic_payload p;
initiator->initiatorSocket.bind(memory->targetSocket);
initiator->initiatorSocket->b_transport(p, delay);
}
};
it is a bit strange but no matter how many times I tried all materials and maps that I create will appear in the General category material.
That’s my code for the material category.
const TCHAR* Category() { return NULL; }//_T(""); }//GetString(IDS_CATEGORY); }
const MCHAR* GetEntryName() const { return LuxMixMapFriendlyClassName; } //NULL; }
const MCHAR* GetEntryCategory() const {
HINSTANCE hInst = GetModuleHandle(_T("sme.gup"));
if (hInst) {
//Extract a resource from the calling module's string table.
static MSTR category(MaxSDK::GetResourceStringAsMSTR(hInst,
IDS_3DSMAX_SME_MATERIALS_CATLABEL).Append(_T("\\Lux")));
return category.data();
}
else
{
return _T("Maps\\Lux");
}
}
enter code here
Finally, I fix the problem, honestly, 3dsmax needs better documentation.
Just writing the solution if this is the case for someone else.
All the code is perfectly correct but in order to apply there is one class that should be called that is optional but not work without it. Also, no error if you not calling it. ( a bit funny )
first, in public classDesc2 i add the "public IMaterialBrowserEntryInfo"
class Lux_AddClassDesc : public ClassDesc2, public IMaterialBrowserEntryInfo
hen inside the class add.
FPInterface* GetInterface(Interface_ID id) {
if (IMATERIAL_BROWSER_ENTRY_INFO_INTERFACE == id) {
return static_cast<IMaterialBrowserEntryInfo*>(this);
}
return ClassDesc2::GetInterface(id);
}
All other part is exactly the same.
Alright, I have been having this problem for a while and I believe I have pin-pointed where the problem is, but I am not sure how to fix it.
void Unit::AddStatusEffect(StatusEffect effect)
{
// Add status effect and if it effects what actions a unit can do, do it here.
myEffects.push_back(effect);
if( effect.GetEffect == effect.STUN)
{
myCanMove = false;
myCanAttack = false;
myCanCast = false;
}
else if (effect.GetEffect == effect.MUTE)
{
myCanCast = false;
}
else if (effect.GetEffect == effect.BLIND)
{
myCanHit = false;
}
else
{}
}
My problem seems to be with the effect.GetEffect return function within the StatusEffect class. If I ask if(effect.STUN == effect.STUN) I get no errors which is why I believe the function is the problem. The error I get seems to be:
function call missing argument list; use '&StatusEffect::GetEffect' to create a pointer to member
(Here is the class in case there is something in there that may be the problem)
class StatusEffect
{
public:
enum Effect { POISON, BURN, BLEED, FREEZE, MUTE, STUN, BLIND, ATKBOOST, HPREGEN, MANAREGEN, MATKBOOST, DEFENSEBOOST, MAGICDEFENSEBOOST };
private:
Effect myEffect;
public:
////////////////////////////////////////////////////////////////
// Data Retrievers
////////////////////////////////////////////////////////////////
Effect const GetEffect() { return myEffect; }
StatusEffect(void);
~StatusEffect(void);
};
I hope I explained my problem well enough. Everything I read up on didn't seem to help me solve this problem.
In Unit::AddStatusEffect, replace effect.GetEffect by effect.GetEffect()
The difference between effect.GetEffect and effect.GetEffect() is that the first evaluates to a pointer to a member function (the function does not get called) while the second evaluates to the returned value of the function call.
You have to call a method or function by adding parentheses, even if there is no argument.
effect.GetEffect()
Beginning with C++, I've written that simple piece of code, which is designed to serve as a (very basic) logger. This is mainly to try overloading operators.
class Logger {
public:
Logger() : _has_logged_something(false) { };
template <typename T>
friend Logger& operator <<(Logger& logger, T const & value) {
logger._has_logged_something = true;
std::cerr << value;
return logger;
};
private:
bool _has_logged_something;
};
I need to remember when something has been loaded already, in the _has_logged_something instance variable. But this line is causing a very helpful Segmentation fault (core dumped) at runtime. Must be an obvious mistake, but I can't get it.
--
Edit
As this doesn't seem to be a problem with this piece of code, here is how it is used to avoid using singletons (probably not the best code ever, but anyway).
#ifndef _BORDERS_COMMON_LOGGER_LOGGER_HH_INCLUDED
#define _BORDERS_COMMON_LOGGER_LOGGER_HH_INCLUDED
#include "common/log/logger.hh"
#include "common/log/event.hh"
namespace {
static borders::common::log::Logger* _global_logger = NULL;
}
namespace borders {
namespace common {
namespace log {
inline bool is_global_instance_initialized() {
return _global_logger != NULL;
};
inline Logger& get_global_instance() {
if (_global_logger == NULL) _global_logger = new Logger;
return *_global_logger;
};
} // namespace log
} // namespace common
} // namespace borders
#define LOG_INFO() (borders::common::log::get_global_instance())
#define LOG_START()
#define LOG_STOP() \
if (borders::common::log::is_global_instance_initialized()) \
delete &borders::common::log::get_global_instance(); \
else \
(void) 0;
#endif // _BORDERS_COMMON_LOGGER_LOGGER_HH_INCLUDED
Given I try to run this with:
LOG_INFO() << "Foo" << "Bar"
Once again, the text gets written on console when I comment out the line I pointed out before.
OK, I got it!
I think. At least I have a guess
See, that line logger._has_logged_something = true is the only line that used the data of the class logger. So my guess is that the class is invalid
I mean that you didn't really create that class. For some reason it wasn't really allocated.
For example if you did:
Logger *log; // see - I didn't put any value to it!
(*log)<<value; // this will do a segmentation fault or something
// ONLY if you have the line logger._has_logged_something = true
This is just an example. There are other options like:
struct blah{
blah(Logger &log):logger(log);
Logger &logger;
};
blah func(){
Logger log;
return blah(log);
}
...
blah b=func(); // b has an invalid logger in it, because it was destroyed after func
blah.logger << value ; // will do a segmentation fault too
Edit
Just saw your edit. So it seems to be my first example. Specifically, I believe you did LOG_STOP() before you logged.
Edit 2
You have an intrinsic problem in your code. LOG_STOP deletes the logger, but doesn't reset it to NULL. So if you want to restart logging after that, the logger won't be recreated (as get_global_instance checks if the logger is NULL before deciding to create it).
Try changing LOG_STOP to set _global_logger to NULL and see if that fixes it.
I am using this code:
class editbook
{
GtkWidget* _nbook;
std::vector<GtkWidget*> _srcset; //and so on...
...........................................................................................
void editbook::add_page()
{
GtkWidget* tmp = gtk_source_view_new();
_srcset.push_back(tmp);
gtk_notebook_append_page(GTK_NOTEBOOK(_nbook),tmp,gtk_label_new("untitled"));
}
...........................................................................................
void editbook::set_text(const std::string& text)
{
int index = gtk_notebook_get_current_page(GTK_NOTEBOOK(_nbook));
GtkTextBuffer* tbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(_srcset[index]));
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(tbuffer),text.c_str(),-1);
}
Compiles fine. But gives this weird runtime error:
Segementation Fault: return 139
I have traced down the problem to: gtk_text_view_get_buffer(GTK_TEXT_VIEW(_srcset[index]));
NOTE: I am using GtkSourceView instead of GtkTextView, but that may not be a problem because I am gettin the same error when I try GtkTextView.
NOTE: I am using Gtk 2x
NOTE: I am not sure whether to tag this question with C or C++. bec. Gtk+ is a C lib. But I am using C++. So I'll just tag both for now.
The problem in your code could be that the child widget added to GtkNotebook through gtk_notebook_append_page is not visible, try showing the child widget through gtk_widget_show call. Something on these lines :
void editbook::add_page()
{
GtkWidget* tmp = gtk_source_view_new();
_srcset.push_back(tmp);
gtk_widget_show(tmp); //Show the child widget to make it visible
gtk_notebook_append_page(GTK_NOTEBOOK(_nbook),tmp,gtk_label_new("untitled"));
}
When you use gtk_notebook_get_current_page if none of the child widget are visible then it returns -1, which I think might be happening in your case & as index is -1 when you use operator[] which doesn't check for bounds the program crashes. I strongly suggest you use vector::at instead of using operator[] so that you get std::out_of_range exception during run time to indicate the problem. You could use:
void editbook::set_text(const std::string& text)
{
int index = gtk_notebook_get_current_page(GTK_NOTEBOOK(_nbook));
GtkTextBuffer* tbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(_srcset.at(index)));
gtk_text_buffer_set_text(GTK_TEXT_BUFFER(tbuffer),text.c_str(),-1);
}
Hope this helps!