I have a problem with the example command plugin from the Maya 2013 API The code for the plugin have been split into a .h and a .cpp file for clarity, but should be otherwise correct.
pluginCmd.h:
// Include the needed headers.
#include <stdio.h>
#include <maya/MString.h>
#include <maya/MArgList.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
#include <maya/MIOStream.h>
// Class to represent our command.
class commandExample : public MPxCommand
{
public:
commandExample();
virtual ~commandExample();
MStatus doIt( const MArgList& );
MStatus redoIt();
MStatus undoIt();
bool isUndoable() const;
static void* creator();
};
pluginCmd.cpp:
// Include the header for the file.
#include "pluginCmd.h"
// Constructor for the command object.
commandExample::commandExample() {
cout << "In commandExample::commandExample()\n";
}
// Destructor for the command object.
commandExample::~commandExample() {
cout << "In commandExample::~commandExample()\n";
}
// The actual command/work to be performed.
MStatus commandExample::doIt( const MArgList& ) {
cout << "In commandExample::doIt()\n";
return MS::kSuccess;
}
// The creator is called when the command is invoked and sets up the command object.
void* commandExample::creator() {
cout << "In commandExample::creator()\n";
return new commandExample();
}
// Gets called when the plugin is loaded into Maya.
MStatus initializePlugin( MObject obj ) {
// Set plugin registration info: Author, plugin-version and Maya version needed.
MFnPlugin plugin( obj, "Martin Jørgensen", "1.0", "Any" );
plugin.registerCommand( "commandExample", commandExample::creator );
// Print to show plugin command was registered.
cout << "In initializePlugin()\n";
return MS::kSuccess;
}
// Gets called when the plugin is unloaded from Maya.
MStatus uninitializePlugin( MObject obj )
{
MFnPlugin plugin( obj );
plugin.deregisterCommand( "commandExample" );
// Print to show the plugin was unloaded.
cout << "In uninitializePlugin()\n";
return MS::kSuccess;
}
It is compiled successfully on Windows 7 x64 Visual Studio 12 with Maya 2013 x64 libraries.
When it is loaded in the plugin manager, noting happens (it should print the initialize status). But when It is unloaded, the initialize print shows up. Does anyone have a clue to why this is?
I'm having the same trouble when writing a plugin using Visual Studio 2015 and Maya 2016 x64.
The suggested workaround
cout << "Something out" << endl;
doesn't seem to work anymore.
I figured out that stuff written to cerr does show up in Maya's output window.
So as a temporary workaround I redirected cout to cerr:
cout.rdbuf(cerr.rdbuf());
Not ideal, but at least we get to see the output...
Tried using:
cout << "Something out" << endl;
as PeterT suggested in a comment, which works.
As a bonus I have realised that it did not "hang" when the command was called, it was because the command object was still active in the undo/redo history. This was a mistake in my ability to grasp Maya's workings.
Related
Recently I had alot of graphic driver issues, so today I used Display Driver Uninstaller to remove my Nvidia drivers and do a clean install. All good, but now when I try to compile one of my programs I get the following error:
"nvd3dum.pdb could not be found in the selected paths" (exception thrown)
What I tried so far:
reinstall the Nvidia drivers(again), since its a Nvidia file that should be the problem?
repair visual studio and update
download all symbols via windows server (Tools->Debugging->Symbols->Server)
I use the boost lib, SDL2(+image,audio,ttf,net),lua/c++ binding, its an "older" project created with VS2015
I tried another program(also SDL2), I get the same warning but it doesnt throw any exception and works fine.
Apparently the error is caused by a second thread:
LoadingScreen.start();
Stuff.Load(); //load SDLTextures
LoadingScreen.end();
//-----------
class LoadingScreen
{
public:
LoadingScreen();
void start() {
mIsActive = true;
mThread = std::thread(&LoadingScreen::render, this);
std::cout << "Start: Loading Screen" << std::endl;
}
void end() {
mIsActive = false;
mThread.join();
std::cout << "End: Loading Screen" << std::endl;
}
private:
void render()
{
while (mIsActive)
{
SDL_RenderClear(gRenderer);
mLoading.render(NULL,angle);
SDL_RenderPresent(gRenderer);
angle = angle + 1.25;
}
}
int mPercent;
std::thread mThread;
bool mIsActive = true;
DefaultTexture mLoading;
};
I'm following this tutorial in the official PCL documentation for the class PCLVisualizer:
http://pointclouds.org/documentation/tutorials/pcl_visualizer.php
and I'm having troubles with the keyboard acquisition: when I select the render window, where the pointcloud is displayed, and try to press "r" or "q", nothing happens and when I try to press the mouse left button, the following text is displayed:
Left mouse button released at position (413, 475)
and the following error is raised (at runtime):
Assertion failed: (px != 0), function operator->, file /usr/local/include/boost/smart_ptr/shared_ptr.hpp, line 687.
Abort trap: 6
I saw that this kind of error happens when you don't initialize the boost::shared_ptr in the declaration of the variable. But in the code listed in the documentation the variable is well defined, so I suppose that the problem concerns the shared_ptr.hpp library, or it isn't?
I've searched over the Internet for a solution, but I haven't found nothing that could solve the issue.
Is there someone that is capable of acquiring keystrokes in the pointcloud's render window by running it on OS X?
If the question is not clear, please let me know.
Thanks a lot for any help or information!
You do not show any code so it's hard to tell what's wrong in your program.
Here is a working example, tested on Ubuntu 14.04 with PCL latest trunk (VTK trunk):
#include <iostream>
#include <pcl/visualization/pcl_visualizer.h>
void keyboardEventOccurred(const pcl::visualization::KeyboardEvent &event, void* viewer_void)
{
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = *static_cast<boost::shared_ptr<pcl::visualization::PCLVisualizer> *>(viewer_void);
if (event.getKeySym() == "r" && event.keyDown())
std::cout << "'r' was pressed" << std::endl;
if (event.getKeySym() == "h" && event.keyDown())
std::cout << "'h' was pressed" << std::endl;
}
void mouseEventOccurred(const pcl::visualization::MouseEvent &event, void* viewer_void)
{
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = *static_cast<boost::shared_ptr<pcl::visualization::PCLVisualizer> *>(viewer_void);
if (event.getButton() == pcl::visualization::MouseEvent::LeftButton &&
event.getType() == pcl::visualization::MouseEvent::MouseButtonRelease)
std::cout << "Left mouse button released at position (" << event.getX() << ", " << event.getY() << ")" << std::endl;
}
int main()
{
pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer);
viewer->addCoordinateSystem();
viewer->registerKeyboardCallback(keyboardEventOccurred, (void*)&viewer);
viewer->registerMouseCallback(mouseEventOccurred, (void*)&viewer);
viewer->spin();
}
Note that some key-strokes are already used by the PCL visualizer for some actions (press h for more details), but it does not prevent you from using them as well.
This is a fairly simple problem I can't get my head around. It was working before and suddenly now that I'm using std::cout, in the Visual Studio 2013 output window I do not see the output, but I see a bunch of background executions happening. I feel I have messed up something. This is App Game Kit project using C++.
Here's the simple code to output:
#include "template.h"
#include <iostream>
using namespace AGK;
app App;
void app::Begin(void)
{
agk::SetVirtualResolution (1024, 768);
agk::SetClearColor( 151,170,204 );
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);
std::cout << "Hello"; // SIMPLE PRINT
}
void app::Loop (void)
{
agk::Print( agk::ScreenFPS() );
agk::Sync();
// std::cout << "Hello"; // TRIED HERE TOO (works like update() in Unity3D)
}
This is what my debug window is showing, instead of printing "Hello":
FYI, the program is working perfectly without any errors. Am I looking at the wrong window? where can find my output?
for logging, i write my entries to a file. here is the Contents of my log method in cpp:
void MyFileUtils::log(string msg)
{
ofstream log("logfile.txt", ios_base::app | ios_base::out);
log << msg << endl;
return;
}
i then just call this whenever i want to log something. i have it as a singleton. Then i just look in my media subfolder to see the contents of logfile.txt
Try using this before you return from the method:
log.flush();
log.close();
I'm struggling with creating a window with the GLFW 3 function, glfwCreateWindow.
I have set an error callback function, that pretty much just prints out the error number and description, and according to that the GLFW library have not been initialized, even though the glfwInit function just returned success?
Here's an outtake from my code
// Error callback function prints out any errors from GFLW to the console
static void error_callback( int error, const char *description )
{
cout << error << '\t' << description << endl;
}
bool Base::Init()
{
// Set error callback
/*!
* According to the documentation this can be use before glfwInit,
* and removing won't change anything anyway
*/
glfwSetErrorCallback( error_callback );
// Initialize GLFW
/*!
* This return succesfull, but...
*/
if( !glfwInit() )
{
cout << "INITIALIZER: Failed to initialize GLFW!" << endl;
return false;
}
else
{
cout << "INITIALIZER: GLFW Initialized successfully!" << endl;
}
// Create window
/*!
* When this is called, or any other glfw functions, I get a
* "65537 The GLFW library is not initialized" in the console, through
* the error_callback function
*/
window = glfwCreateWindow( 800,
600,
"GLFW Window",
NULL,
NULL );
if( !window )
{
cout << "INITIALIZER: Failed to create window!" << endl;
glfwTerminate();
return false;
}
// Set window to current context
glfwMakeContextCurrent( window );
...
return true;
}
And here's what's printed out in the console
INITIALIZER: GLFW Initialized succesfully!
65537 The GLFW library is not initialized
INITIALIZER: Failed to create window!
I think I'm getting the error because of the setup isn't entirely correct, but I've done the best I can with what I could find around the place
I downloaded the windows 32 from glfw.org and stuck the 2 includes files from it into minGW/include/GLFW, the 2 .a files (from the lib-mingw folder) into minGW/lib and the dll, also from the lib-mingw folder, into Windows/System32
In code::blocks I have, from build options -> linker settings, linked the 2 .a files from the download. I believe I need to link more things, but I can figure out what, or where I should get those things from.
I tried reinstalling codeblocks and mingw, which solved the issue.
Seems like GLFW3 doesn't like having previous versions installed at the same time for some reason, so if anyone else is having a similar problem, you might want to try that.
I experienced similar problems in Cocos 3.8.1 and 3.10.
I have never installed codeblocks or mingw, so it did not make sense to install them for me.
The GLFW.lib file in the cocos directory is out of date.
http://www.glfw.org/download.html, and replace the lib file in your project with the latest one, and it may resolve your error.
I just recently started playing around with SFML and I wrote this simple program.
I'm using visual studio 2010 btw.
The program compiles and runs fine when using the "start debugging" option.
but if I open the .exe file as if I was running a normal desktop application or something, it will crash on exit.
I've spent a while trying to figure it out but all I can say is that it's probably a heap corruption.
here's all the code:
#include <iostream>
#include <sstream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
void moveSquare();
void avgFPS();
class displayFPS : public sf::Thread{
public:
private:
virtual void Run();
};
int checkEvent(sf::RenderWindow &win){
sf::Event Event;
while(win.GetEvent(Event)){
// Window closed
if (Event.Type == sf::Event::Closed){
return 0;
}
// Escape key pressed
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)){
return 0;
}
}
return -1;
}
sf::RenderWindow win(sf::VideoMode(800,600,32),"Mario Clone Test");
sf::Image img1(200,200,sf::Color(255,255,0));
sf::Sprite sprite1;
std::stringstream ss;
sf::String fps;
bool threadFPS;
int main(){
sprite1.SetImage(img1);
sprite1.SetCenter(-300,-300);
win.SetFramerateLimit(30);
moveSquare();
win.Close();
sf::Sleep(0.5);
return 0;
}
void moveSquare(){
displayFPS dispFPS;
threadFPS = true;
dispFPS.Launch();
fps.SetSize(20);
while(1){
if(!win.IsOpened() || checkEvent(win) == 0){
threadFPS = false;
dispFPS.Wait();
break;
}
win.Draw(sprite1);
win.Draw(fps);
win.Display();
win.Clear();
if(win.GetInput().IsKeyDown(sf::Key::Left)){
sprite1.Move(-100*win.GetFrameTime(),0);
}
if(win.GetInput().IsKeyDown(sf::Key::Right)){
sprite1.Move(100*win.GetFrameTime(),0);
}
if(win.GetInput().IsKeyDown(sf::Key::Up)){
sprite1.Move(0,-100*win.GetFrameTime());
}
if(win.GetInput().IsKeyDown(sf::Key::Down)){
sprite1.Move(0,100*win.GetFrameTime());
}
}
return;
}
void avgFPS(){
double frames=0.0,avg=0.0;
int j=0;
while(threadFPS){
if(win.GetFrameTime() != 0){
j++;
frames = frames+(1.0/win.GetFrameTime());
avg = frames/j;
}
ss << "avg FPS: " << avg << std::endl << "Arrow Keys to Move" << std::endl << "Press ESC to Exit";
fps.SetText(ss.str());
ss.str("");
}
return;
}
void displayFPS::Run(){
avgFPS();
}
I've had the same issue.
You need to recompile SFML when using VS2010.
Few things for you to try:
If you are suspecting heap corruption, run gflags (found in Debugging Tools for Windows) and enable page heap. Some instructions on how it works can be found here. Basically when page heap is enabled, your app will crash at the point of the memory error, not sometime later.
You said you get a crash on exit. When that happens, I'm assuming windows throws up a crash dialog box. Open one of those links that say something like "see what information is being uploaded". Somewhere among those files will be a minidump of your process. You can load that up in visual studio (open file and hit F5). Sometimes visual studio is glitchy, so another, more reliable but more difficult but more difficult to use alternative is WinDbg, also part of Debugging Tools for Windows.
SFML has multiple versions of their .lib's for release and debug.
Examples:
sfml-audio.lib
sfml-audio-d.lib
sfml-audio-s.lib
sfml-audio-s-d.lib
Make sure you are using the lib without the -d in it.
Also, when you put the .dll's with your exe (assuming you are using the dynamic libraries) make sure to use the normal versions not the debug (-d) versions.
Finally, when you are building the project make sure you build for release and not debug.