evstevemd wrote: ↑Wed Jul 03, 2019 1:14 pmCan you make simple compilable app which demonstrates your problem. That way one can easily test and see the issue. Linking old code does not help and is waste of time for people who try to help!
Only the first link was to my old code. I'm using Git version control hosting on GitHub. So to see the full current code, just go to
https://github.com/AntumDeluge/myabcs. My first links were to previous commits that demonstrated how the program had been working correctly in the past. The links after that were to the code as it is (or as it was at the time).
doublemax wrote: ↑Wed Jul 03, 2019 4:13 pmAfter reading your code, the most likely reason for the failure is what alys666 wrote: The definitions of IDs in a header file is a no-go because it will get loaded multiple times and a different ID for ID_SOUNDEND (and all others) will be created.
I understand. I thought that making it
static const fixed that, but I see now that it does not. I will switch to using an
enum or defining the values in a .cpp file.
However, this is my current code that does not use an ID (or rather, it implicitly uses
wxID_ANY):
sound.cpp:
Code: Select all
// event to send to main thread
wxCommandEvent SoundFinishEvent(EVT_SOUND_FINISH);
wxPostEvent(source_window, SoundFinishEvent); // FIXME: event not caught
abc.cpp:
Code: Select all
// sounds finish playing
Bind(EVT_SOUND_FINISH, &MainWindow::OnSoundFinish, this);
Event is still not being caught.....
.....But, as I write this, I think I realize why... and it
IS related to what alys666 was saying. I created the new event type in a header using
wxNewEventType:
Code: Select all
static const wxEventType EVT_SOUND_FINISH = wxNewEventType();
So two different event types are created.
sound.cpp is sending one type, &
abc.cpp is waiting for another. I will post back after I fix this.
--- Edit ---
Yep, that was the problem
. New event code:
event.h:
Code: Select all
#ifndef MYABCS_EVENT_H
#define MYABCS_EVENT_H
#include <wx/event.h>
extern const wxEventType EVT_SOUND_FINISH;
#endif /* MYABCS_EVENT_H */
event.cpp:
Code: Select all
#include "event.h"
const wxEventType EVT_SOUND_FINISH = wxNewEventType();
Thank you alys666 & doublemax, problem solved.
--- Edit ---
Initially, I marked my post as the correct answer. But I'm going to mark alys666's as such, because I think that would have solved the problem at the time. I wasn't creating a new event type then, but rather using the ID to catch the event. So declaring the ID as
extern & defining in a separate .cpp file would have fixed it. Thank you alys666.
--- Edit ---
For reference, here is the new ID code:
id.h:
Code: Select all
#ifndef MYABCS_ID_H
#define MYABCS_ID_H
#include <wx/utils.h> // wxNewId();
extern const int ID_EXIT;
extern const int ID_ABC;
extern const int ID_FOOD;
extern const int ID_ANIMALS;
extern const int ID_MUSIC;
extern const int ID_TOYS;
extern const int ID_HELP;
extern const int ID_ABOUT;
extern const int ID_SPACE; // Id used in threads for space
//extern const int ID_TAB; // Id used in threads for tab
extern const int ID_KEY; // Id used in threads for keypress
extern const int ID_OTHER; // Id used in other threads
extern const int ID_WINDOW;
extern const int ID_BG;
extern const int ID_CHANGELOG;
extern const int ID_LOG;
#endif /* MYABCS_ID_H */
id.cpp:
Code: Select all
#include "id.h"
const int ID_EXIT = wxNewId();
const int ID_ABC = wxNewId();
const int ID_FOOD = wxNewId();
const int ID_ANIMALS = wxNewId();
const int ID_MUSIC = wxNewId();
const int ID_TOYS = wxNewId();
const int ID_HELP = wxNewId();
const int ID_ABOUT = wxNewId();
const int ID_SPACE = wxNewId(); // Id used in threads for space
//const int ID_TAB = wxNewId(); // Id used in threads for tab
const int ID_KEY = wxNewId(); // Id used in threads for keypress
const int ID_OTHER = wxNewId(); // Id used in other threads
const int ID_WINDOW = wxNewId();
const int ID_BG = wxNewId();
const int ID_CHANGELOG = wxNewId();
const int ID_LOG = wxNewId();