用vs2012编写物理引擎小球程序,运行时内存访问发生冲突。

环境:win8.1 + vs2012 + cocos2d-x-3.0beta2
跟着极客学院学习cocos2d-x的开发,运行程序时出错了:

各位能不能帮我看看是什么原因?

+_+ 图竟然挂了。我要怎么上传呢?

这是第一个图。

这是错误提示信息。

HelloWorldScene.h代码如下:

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

class HelloWorld : public cocos2d::Layer
{
private:
    cocos2d::Size visiblesize;
public:
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* createScene();

    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    void onEnter();

    void addEdges();

    void addBall(float positionX, float positionY);
    
    // a selector callback
    void menuCloseCallback(Object* pSender);
    
    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);
};

#endif // __HELLOWORLD_SCENE_H__


```

HelloWorldScene.cpp代码如下:

#include "HelloWorldScene.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::createWithPhysics();
    scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
    
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
 //   Size visibleSize = Director::getInstance()->getVisibleSize();
 //   Point origin = Director::getInstance()->getVisibleOrigin();

 //   /////////////////////////////
 //   // 2. add a menu item with "X" image, which is clicked to quit the program
 //   //    you may modify it.

 //   // add a "close" icon to exit the progress. it's an autorelease object
 //   auto closeItem = MenuItemImage::create(
 //                                          "CloseNormal.png",
 //                                          "CloseSelected.png",
 //                                          CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
 //   
    //closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
 //                               origin.y + closeItem->getContentSize().height/2));

 //   // create menu, it's an autorelease object
 //   auto menu = Menu::create(closeItem, NULL);
 //   menu->setPosition(Point::ZERO);
 //   this->addChild(menu, 1);

 //   /////////////////////////////
 //   // 3. add your codes below...

 //   // add a label shows "Hello World"
 //   // create and initialize a label
 //   
 //   auto label = LabelTTF::create("Hello World", "Arial", 24);
 //   
 //   // position the label on the center of the screen
 //   label->setPosition(Point(origin.x + visibleSize.width/2,
 //                           origin.y + visibleSize.height - label->getContentSize().height));

 //   // add the label as a child to this layer
 //   this->addChild(label, 1);

 //   // add "HelloWorld" splash screen"
 //   auto sprite = Sprite::create("HelloWorld.png");

 //   // position the sprite on the center of the screen
 //   sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

 //   // add the sprite as a child to this layer
 //   this->addChild(sprite, 0);
    visiblesize = Director::getInstance()->getVisibleSize();
    
    return true;
}

void HelloWorld::onEnter()
{
    Layer::onEnter();
    addEdges();
    addBall(visiblesize.width/2, visiblesize.height/2);
}

void HelloWorld::addEdges()
{
    auto body = PhysicsBody::createEdgeBox(visiblesize, PHYSICSBODY_MATERIAL_DEFAULT, 3);
    auto edgeshape = Node::create();
    edgeshape->setPhysicsBody(body);
    edgeshape->setPosition(visiblesize.width/2, visiblesize.height/2);
    addChild(edgeshape);
}

void HelloWorld::addBall(float positionX, float positionY)
{
    auto ball = Sprite::create("ball.jpg");
    ball->setPhysicsBody(PhysicsBody::createBox(ball->getContentSize()));
    ball->cocos2d::Node::setPosition(positionX,positionY);
    addChild(ball);
}


void HelloWorld::menuCloseCallback(Object* pSender)
{
    Director::getInstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}


```
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

class HelloWorld : public cocos2d::Layer
{
private:
    cocos2d::Size visiblesize;
public:
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* createScene();

    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  

    void onEnter();

    void addEdges();

    void addBall(float positionX, float positionY);
    
    // a selector callback
    void menuCloseCallback(Object* pSender);
    
    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);
};

#endif // __HELLOWORLD_SCENE_H__



```

图片不存在

我不是重新挂在2楼和3楼吗?

游戏里面精灵图片不存在,表达错误了

什么意思?我不懂。你要什么图片,我给你截,麻烦你给我找找原因。

ball2.jpg这张图片有吗?

b是空指针,目测图不存在,或者路径错误

你这么一说,我是把图片直接从桌面拉到resource那里的。不行吗?

b是空指针?路径错误了我要怎么做?我是直接把图片直接从桌面拉到resource那里的。

原因是我把图片发错了文件夹,已经解决了。谢谢。